hi, i have following lines in bash.
#!/bin/bash mount -t vfat /some/usb_devfs/device /mnt/usb cd /mnt/usb
But somehow the 'cd' command behaves very strangely. if after cd /mnt/usb i put 'pwd' it shows '/mnt/usb' but, instead of 'pwd' if i put 'ls' it shows the listing of dir from which the script is executed. very strange.
Harshal wrote:
hi, i have following lines in bash.
#!/bin/bash mount -t vfat /some/usb_devfs/device /mnt/usb cd /mnt/usb
Not too sure but I feel there should be a last line that exits you from the script.
Regards,
Rony.
___________________________________________________________ Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
On Tue, Aug 30, 2005 at 08:29:16PM +0530, Rony Bill wrote:
Harshal wrote:
hi, i have following lines in bash. #!/bin/bash mount -t vfat /some/usb_devfs/device /mnt/usb cd /mnt/usb
Not too sure but I feel there should be a last line that exits you from the script.
No. There is no such line. If there is, it's not required.
On Mon, 2005-08-29 at 15:02 +0530, Harshal wrote:
#!/bin/bash mount -t vfat /some/usb_devfs/device /mnt/usb cd /mnt/usb
But somehow the 'cd' command behaves very strangely. if after cd /mnt/usb i put 'pwd' it shows '/mnt/usb' but, instead of 'pwd' if i put 'ls' it shows the listing of dir from which the script is executed. very strange.
$ cat bin/test.sh #!/bin/bash cd /mnt/sda; ls -a
I tested your script (a bit modified) and don't see the behaviour you describe. I executed the script from my $HOME which has many dirs and files.
ls -a shows . and .. (since /mnt/sda is empty) and pwd (replacing ls -a) shows /mnt/sda.
#!/bin/bash mount -t vfat /some/usb_devfs/device /mnt/usb cd /mnt/usb
I tried this script in the following manner: *$cat test.sh* *#!/usr/bin/bash* *cd /opt* *pwd* *ls* When the script is executed, it gives the pwd as /opt and the ls lists the contents of /opt. But when I execute pwd from shell, it gives the directory from where I executed the script. Reason: The script is executed in a new shell. When it finishes the execution, the shell is killed automatically. Vidyadutt.
On 8/31/05, Vidyadutt S vidyadutt@gmail.com wrote:
When the script is executed, it gives the pwd as /opt and the ls lists the contents of /opt. But when I execute pwd from shell, it gives the directory from where I executed the script. Reason: The script is executed in a new shell. When it finishes the execution, the shell is killed automatically. Vidyadutt. --
i don't have any problem with pwd, in the script the pwd shows /mnt/usb, but if i put ls right after pwd in the script, it lists the files of dir from which the script is executed.
On 8/31/05, Vidyadutt S vidyadutt@gmail.com wrote:
When the script is executed, it gives the pwd as /opt and the ls lists the contents of /opt. But when I execute pwd from shell, it gives the directory from where I executed the script. Reason: The script is executed in a new shell. When it finishes the execution, the shell is killed automatically. Vidyadutt.
suprising i can achive the same thing, with
mkdir ll cd ll who > who.txt pwd ls
but instead of 'mkdir ll' if i put the /some_devfs/usb_device, then that ls command won't work. still clueless.
Vidyadutt S wrote:
#!/bin/bash mount -t vfat /some/usb_devfs/device /mnt/usb cd /mnt/usb
I tried this script in the following manner: *$cat test.sh* *#!/usr/bin/bash* *cd /opt* *pwd* *ls* When the script is executed, it gives the pwd as /opt and the ls lists the contents of /opt. But when I execute pwd from shell, it gives the directory from where I executed the script.
adding to that, on can use source command to run script in same shell
Reason: The script is executed in a new shell. When it finishes the execution, the shell is killed automatically. Vidyadutt.
HTH Supreet
When the script is executed, it gives the pwd as /opt and the ls lists the contents of /opt. But when I execute pwd from shell, it gives the directory from where I executed the script.
remove the intial #!/bin/sh and try running the script as
#> . script-name
to run the commands in the current shell instead of a subshell. Basically the source command as mentioned by Supreet.
regards, C
On Wednesday 31 August 2005 06:57, Chetan S wrote:
execute it with ./
subshell. Not all changes in subshell reflect to parent shell. Try referring Advanced Bash Scripting guide for more answers.
IMHO, #!/bin/bash doesn't mean that the script will run in a sub shell. It just tells the shell which interpreter to use while executing the script.