Shell script doubts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script doubts
# 1  
Old 04-28-2012
Shell script doubts

Hello please kindly solve these doubts i have about the following scripts

Code:
Script 1
//Shell script that accepts arguments and prints them in reverse order//
echo "number of arguments"
len=$#;
while [ $len -ne 0 ]
do
   eval echo \$$len
   len=`expr $len - 1`
done

---------
Output
Code:
$sh test.sh a b
b
a

1.what is \$$len .what is the significance of the escape sequence


Script 2
Code:
//Bundle shell script that accepts file name as arguments and create a shell scipr that has the file \
as well as the code to recreate the files.Thus if the script generated by your script is executed \
it would recreate the original file//

echo "#to bundle ,sh this file"
for i in $*
do
   echo "echo $i 1>&2"
   echo "cat > $i <<'end of $i'"
   cat $i
   echo " end of $i"
done


---------------
Output
$cat f1
hi
$cat f2
hello
$sh test.sh f1 f2 >new.sh
$rm f1 f2
$sh new.sh
f1
f2

1.Even though the 1st line is a simple print statement if i write something different I get the following error message :
Code:
"new.sh: line 1: to: command not found".

Can u tell me why do i get this message
2.In the 4th line what does 1>&2 mean
3.Is "end of" a command and what does "<<" mean.

Last edited by vbe; 04-30-2012 at 10:54 AM.. Reason: Beautify text and code, typos extra code tags
# 2  
Old 04-30-2012
please help me with this
# 3  
Old 04-30-2012
Read and learn what is here: (will explain 3, and perhaps 1...)
Here document - Wikipedia, the free encyclopedia

1>&2 : Redirect STDOUT to STDERR (???)
# 4  
Old 04-30-2012
Code:
eval echo \$$len


The parameters of a shell script are available as $1, $2...$n
So by escaping the dollar we get a literal "$" followed by the position we wish to display.
evaluating this returns the value of the parameter at that position.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Some doubts about resizing fs's in HP-UX

Hello, I'm new to HP-UX and I'm not sure about some concepts related to resizing fs's under this OS. First of all I'm only asking about resizing ONLINE, it means, without having to umount the fs nor rebooting, etc. Q1. I've read that in order to resize a fs online there are 2 requirements:... (3 Replies)
Discussion started by: asanchez
3 Replies

2. AIX

doubts on xcomd

Hi , How to check if a daemon process is running or not ? is the lssrc command the right option ? I want to check if xcomd daemon is running or not ? lssrc -a | grep xcomd is of no use. Though I am able to sense that xcomd is running there is no output from lssrc command. Do I... (2 Replies)
Discussion started by: BalajiUthira
2 Replies

3. AIX

Doubts on SMIT

Hi All, Have a few doubts on SMIT. 1. Is SMIT available in seperate packages if it is not installed by default with the AIX ? 2. how to check the smit version.. is there anything of that kind ? 3. what is the effect of smit.cat file ? 4. What are all the files present in /etc/objrepos/... (4 Replies)
Discussion started by: BalajiUthira
4 Replies

4. Shell Programming and Scripting

shell scripting doubts

Hello All, I am working in a reputed software firm,currently working on testing platform (manual and automation).But I am very much intersted in unix and shell scripting,I feel that I am good at beginner level of shell scripting,still I want to practise shell scripting to become excel in it.I... (1 Reply)
Discussion started by: maheshglm
1 Replies

5. Shell Programming and Scripting

Doubts about variables

Hi, If I have a variable in a configuration file like this: BTS=53,1-2-3-6 export BTS As might get each of the variables in this parameter? "53" "1" "2" .... (3 Replies)
Discussion started by: danietepa
3 Replies

6. Shell Programming and Scripting

Few Important doubts and questions..(Unix/Shell)

Hi All, I have a few questions which I am unable to solve/answer. Please help me with them:- Command in Unix to determine if a Host is connected to the internet ? If a parenet process is killed what happens to the child process? How do I print the first 10 lines of a file in the... (1 Reply)
Discussion started by: shubhranshu
1 Replies

7. Shell Programming and Scripting

awk, sed and a shell doubts

Hi, I have 3 doubts which I posted it here. Doubt 1: I have a file containing data: 22 -73 89 10 99 21 15 -77 23 63 -80 91 -22 65 28 97 I am trying to print the fields in the reverse order and replace every field by its absolute (positive) value (ie.) I am looking for output: 10... (8 Replies)
Discussion started by: royalibrahim
8 Replies

8. UNIX for Dummies Questions & Answers

Unix doubts

Hi All, 1. how and who calls .profile when you login 2. what is PPID and what means by PPID = 0 Thanks in Advance (2 Replies)
Discussion started by: ravi.sadani19
2 Replies

9. Shell Programming and Scripting

doubts in crontab

Hi All, I am tring to set a shedule for cron to execute my script in every 15 min, n want a mail alert on my mail id if cron fails to get data as input for my script, how can i set that? Thanks in advance Subin (1 Reply)
Discussion started by: subin_bala
1 Replies

10. UNIX for Dummies Questions & Answers

unix doubts

Write unix command to list or view auto links (0 Replies)
Discussion started by: ashishshah.engg
0 Replies
Login or Register to Ask a Question