Unix scripting related queries

Hi,

I need to know wat does if ! >$tmp_out in the below script mean:

tmp_out=$SCRATCH_DIR/file_cat.$$.tmp
   if
      ! > $tmp_out
   then
      print "Could not initialize temorary file" >&2
      my_exit_code=21
      break
 fi

---------- Post updated at 04:28 AM ---------- Previous update was at 04:26 AM ----------

Also wat does this line suggest in a script:

print "\nTrouble removing file" >&2 --> &2 ????

Somebody is trying to test if a temp file already exists. Though I don't know this type of syntax and can't get it to work. Easiest and most easy to read might be to use the -e switch of the test command or inside the if -condition with single or double square brackets.

Also use code tags when writing code, data or logs etc. thanks.

With you second snippet of code, I am not sure what is still code and what did you edit in that line. You want to know what >&2 means?

! >$tmp.out means the negation of the return code of the command >$tmp.out . This latter command writes an empty string to the file "$tmp.out" . If this is successful then the return code is 0, if not it is >0 (1 in this case). The ! renders a negation of this value so 0 becomes 1 and a value 1 becomes 0.
So in short if the action is unsuccessful and the return code is 1, then the negation becomes 0 and therefore the if statement gets executed...

print "\nTrouble removing file" >&2 --> &2

Is Kornshell syntax. It means write the string to stderr. The second part contains an error, there should not be a space between > and &

1 Like

ya i wanted to know abt &2.

Seems I was barking up the wrong tree, sorry :wink: Forget my answer and check Scrutinizers. Learned something new^^.