Can anyone explain plz


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Can anyone explain plz
# 1  
Old 03-27-2007
Can anyone explain plz

HI,

Can anyone explain to me how does the following command work - >

current_dir=`cd \`/usr/bin/dirname $0\` && pwd`

Regards,
Ranga
# 2  
Old 03-27-2007
Code:
$ cat spt
echo $0
current_dir=`cd \`/usr/bin/dirname $0\` && pwd`
echo "current_dir="$current_dir
$ /db2home/training/anbu/spt
/db2home/training/anbu/spt
current_dir=/db2home/training/anbu

cd \`/usr/bin/dirname $0\` cd to script directory
pwd assign the directory to current_dir where script resides.

Instead of above code you can use this
Code:
current_dir=`/usr/bin/dirname $0`


Last edited by anbu23; 03-27-2007 at 04:04 AM..
# 3  
Old 03-27-2007
Help needed

Hi ,

Thanks for your reply. One more doubt

Does “cd \`/usr/bin/dirname $0\` cd to script directory” will the same change the directory or jus gives u the directory name?

Regards,
Ranga
# 4  
Old 03-27-2007
cd \`/usr/bin/dirname $0\` just change directory

In the following code this cd is done within `..` which will open new shell and change directory. So if you come out this line you will be in the same directory as before executing this line.
Code:
current_dir=`cd \`/usr/bin/dirname $0\` && pwd`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can someone explain this for me?

Can someone do me a favour and explain the following for me: ((r=$RANDOM%$n+1)) I know what $RANDOM does but what is % sign and what does it do with %$n+1? (2 Replies)
Discussion started by: bashily
2 Replies

2. Shell Programming and Scripting

Plz explain the process of this code....

Hi Unix Gurus, Please explain the processing done by the code mentioned below: for (i=1;i<=59;i++) { sub(/ *$/,"", $i) } newrec_key = $2 new_line = $0 if (empty_oldfile==1) { #newly added record ++num_add print "Added key: ", newrec_key > LogFile #print out... (4 Replies)
Discussion started by: ustechie
4 Replies

3. Shell Programming and Scripting

plz explain the execution flow

CODE file=/tmp/rap54ibs2sap.txt trap "rm $file; exit" 0 1 2 3 15 trap rm $file execution result trap -- 'rm /tmp/rap54ibs2sap.txt; exit' EXIT trap -- 'rm /tmp/rap54ibs2sap.txt; exit' SIGHUP trap -- 'rm /tmp/rap54ibs2sap.txt; exit' SIGINT trap -- 'rm /tmp/rap54ibs2sap.txt;... (1 Reply)
Discussion started by: rrd1986
1 Replies

4. Homework & Coursework Questions

Could anyone help explain this?

1. The problem statement, all variables and given/known data: I have a retake assignment to complete for my computer networks and OS class. This isn't really my area, had I known last year I could have swapped it for a different module I would have done so. I'm determined to get through it... (6 Replies)
Discussion started by: Squall Moogle
6 Replies

5. Shell Programming and Scripting

Explain this AWK script plz

Hi frnds, one my frnds has given resolution for my problem as below. it working great , but i couldnt understand somethings in the script. Why ++ operator after the function calling. how these each block working. will each run for each input line sequencially or one block for all the lines... (9 Replies)
Discussion started by: Gopal_Engg
9 Replies

6. AIX

can anyone explain this?

this is the mksys b script.... can anyone explain .. what # and 1 in if condition this is the first line of the script... it is not from middle of the script.... if then echo "Not enough parameters, need a client name for mksysb" Usage="Usage: $0 <client name>" ... (2 Replies)
Discussion started by: honeym210
2 Replies

7. Shell Programming and Scripting

explain plz

can u explain this step by step........plz...will it do the same for I in *.tar.gz; do A=`basename $I .tar.gz` mkdir $A cp marking-guide ${A}/$A cd $A gunzip -c ../$I | tar xf - cd.. done thnx __________________ (2 Replies)
Discussion started by: avikal
2 Replies

8. Shell Programming and Scripting

perl doubt plz explain....

hi all i wrote a shell script which uses perl script my code is : >cat filename | while read i >do >perl -e 'require "/home/scripts/abc.pl" ; abc("$i")' >done perl script used will simply check syntax of Cobol programs but it didn't work for me so i asked my colleague he suggested... (1 Reply)
Discussion started by: zedex
1 Replies

9. UNIX for Dummies Questions & Answers

explain command plz

echo -n "1. Updating Password Policy in OID..." | tee -a $logfile set ldap_v1 = `ldapsearch -b "" -h $oid_host -p $oid_port -D "cn=orcladmin" -w $admin_pwd -s sub "cn=PwdPolicyEntry" dn | head -1` echo "dn:$ldap_v1" > ldap1.out echo "changetype:modify" >> ldap1.out echo... (2 Replies)
Discussion started by: maoro
2 Replies

10. UNIX for Dummies Questions & Answers

plz Help How should I configure cc compiler output file plz help???

i.e configuration of C compiler :confused: (4 Replies)
Discussion started by: atiato
4 Replies
Login or Register to Ask a Question