Unix scripting related queries


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix scripting related queries
# 1  
Old 03-20-2012
Unix scripting related queries

Hi,

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

Code:
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:

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

Moderator's Comments:
Mod Comment Use code tags, see PM, thanks.

Last edited by zaxxon; 03-20-2012 at 06:46 AM.. Reason: code tags
# 2  
Old 03-20-2012
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?
# 3  
Old 03-20-2012
! >$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...

Code:
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 &
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 03-20-2012
Quote:
Originally Posted by zaxxon
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?

ya i wanted to know abt &2.
# 5  
Old 03-20-2012
Seems I was barking up the wrong tree, sorry Smilie Forget my answer and check Scrutinizers. Learned something new^^.

Last edited by zaxxon; 03-20-2012 at 07:55 AM.. Reason: added note
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using shell scripting for making queries on postgres sql

I have a situation where I have a list of airplanes that make a series of flights. Therefore I am looking up the different flights that each airplane makes based on a postgres sql query: select flightid from plane where airplane='DELTAx' As a result I get a series of flight numbers... (0 Replies)
Discussion started by: JSNY
0 Replies

2. Shell Programming and Scripting

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX?

Please share the doc asap as very urgently required. (1 Reply)
Discussion started by: 24ajay
1 Replies

3. Shell Programming and Scripting

Help related to clearing of shell scripting doubt

Hello Gurus, Can anybody please help me to understand as what does this lines(Marked in bold) does: _TABLESPACE_OFFLINE=`cat ${_tmp_res} | grep -iv "online" | grep -v "^*$" | grep -iv "SQL>"` ------->1 if ;then _tmp_tablespace_status=1 ... (1 Reply)
Discussion started by: hitesh1907
1 Replies

4. Shell Programming and Scripting

need downloading related help...but its not related to unix

Hi All, I am trying to dowmload the zip file "zkManageCustomers.zip " but i dont have access. Can anyone help me to download this file See the below link- http://www.ibm.com/developerworks/opensource/library/wa-aj-open/index.html?ca=drs- Please help me as early as... (1 Reply)
Discussion started by: aish11
1 Replies

5. Shell Programming and Scripting

How to extract queries using UNIX shell script?

Hi, I have an input file which have many lines,from which i need to extract only the complete sql statements and write this alone to an output file. please help us in this. Regards Meva (7 Replies)
Discussion started by: meva
7 Replies

6. Solaris

Queries related to Solaris and opensolaris

1.Is Solaris open source or closed source? From my knowledge it is a mix of both, since it implements GNU applications like bash, grub, and GNOME, firefox, etc. Could someone please throw some more information on this .. 2.If opensolaris is a complete open source OS, does it not mean that it also... (2 Replies)
Discussion started by: saagar
2 Replies

7. Solaris

Queries related to runlevels and fdisk utility...

Hello friends.. I have 2 doubts as follows: 1.What is the difference between init s (single user mode), init S (single user mode), init 1 (single user mode), and again failsafe mode. As far as I have seen, init s and init 1 does the same thing: putting the system in maintenance mode asking for... (2 Replies)
Discussion started by: saagar
2 Replies

8. Shell Programming and Scripting

Scripting related .

Could any body give the solution/script to get the below... 1.script will run and detcect the files having 0kb size , and give the solution in a out put file.(Will search the file in the path let say /abc/M/) 2.Same as the above also send a mail to your mails id , with the file name stating... (13 Replies)
Discussion started by: alexMar
13 Replies

9. Forum Support Area for Unregistered Users & Account Problems

How to post a new thread (Regarding Unix related doubts) in Unix Forums

How to post a new thread (Regarding Unix related doubts) in Unix Forums. I registered my id but I am unable to post my Questions to Forum. Thanks & Regards, indusri (1 Reply)
Discussion started by: indusri
1 Replies
Login or Register to Ask a Question