Logo 
Search:

Unix / Linux / Ubuntu Forum

Ask Question   UnAnswered
Home » Forum » Unix / Linux / Ubuntu       RSS Feeds

Script that will CD, change directory

  Date: Dec 14    Category: Unix / Linux / Ubuntu    Views: 483
  

There is a directory called "avr" off my home directory. So why
doesn't the 2nd for last line take me to that directory. What the heck
am I missing/doing wrong?

#!/bin/bash
#
#
# Script to print user information who currently login , current date
& time
#
clear
echo "Hello $USER"
echo "Today is ";date
echo "Number of user login : " ; who | wc -l
echo "Calendar"
cal
cd ~/avr
exit 0

Share: 

 

2 Answers Found

 
Answer #1    Answered On: Dec 14    

When the bash script exits, you're back where you started because the
process executing the script terminated. :-)

The "cd ~/avr" does work in the script; add a "pwd" between that and
the "exit 0" to reassure yourself.

If you want to actually remain in ~/avr when the script finishes,
remove the "exit 0" and start the script per "source scriptname"
or ". scriptname" (noting there's a space between the "." and the
scriptname.

 
Answer #2    Answered On: Dec 14    

That done it. I'm doing work in a directory several directories down a
chain. Get tired of typing in the path over and over.

 
Didn't find what you were looking for? Find more on Script that will CD, change directory Or get search suggestion and latest updates.




Tagged: