Re: [Way OT] "#!/bin/bash" changes working directory
Dear Jan,
> Hm, this is a bit redundant - it's not necessary to wrap pwd into
> process substitution and echo the results... (...)
Thanks for the comment! It was just something to show the change...
> Besides, the snippet is procuding the desired result here ($pwd, not
> $HOME). AFAICT, bash doesn't read any startup files when called as
> script interpreter in this fashion, so I've got no idea why your bash
> is behaving that way... just out of curiosity, what does
>
> bash -c "readlink /proc/self/cwd"
babbage[~]% bash -c "readlink /proc/self/cwd"
/home/finotti
> return? And which files does bash read on startup? (Try
>
> strace -eopen bash -c "echo 'X'"
Many repeated lines, but, after "uniq":
open("/etc/ld.so.cache", O_RDONLY) = 3
open("/lib/libtermcap.so.2", O_RDONLY) = 3
open("/lib/libdl.so.2", O_RDONLY) = 3
open("/lib/libc.so.6", O_RDONLY) = 3
open("/dev/tty", O_RDWR|O_NONBLOCK|O_LARGEFILE) = 3
open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3
open("/etc/mtab", O_RDONLY) = 3
open("/proc/meminfo", O_RDONLY) = 3
open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = 3
open("/usr/lib/gconv/ISO8859-1.so", O_RDONLY) = 3
open("/home/finotti/.bashrc", O_RDONLY|O_LARGEFILE) = 3
--- SIGCHLD (Child exited) @ 0 (0) ---
open("/home/finotti/local/bash_completion/bash_completion",
O_RDONLY|O_LARGEFILE) = 3
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
--- SIGCHLD (Child exited) @ 0 (0) ---
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
--- SIGCHLD (Child exited) @ 0 (0) ---
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
--- SIGCHLD (Child exited) @ 0 (0) ---
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
open("/usr/share/locale/locale.alias", O_RDONLY) = 3
open("/usr/share/locale/en_US/LC_MESSAGES/bash.mo", O_RDONLY) = -1
ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/bash.mo", O_RDONLY) = -1 ENOENT
(No such file or directory)
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
--- SIGCHLD (Child exited) @ 0 (0) ---
open("/home/finotti/local/bash_completion/bash_completion.d/",
O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
open("/home/finotti/local/bash_completion/bash_completion.d/inkscape",
O_RDONLY|O_LARGEFILE) = 3
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
open("/home/finotti/local/bash_completion/bash_completion.d/m-a",
O_RDONLY|O_LARGEFILE) = 3
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
open("/home/finotti/local/bash_completion/bash_completion.d/make_kpkg",
O_RDONLY|O_LARGEFILE) = 3
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
open("/home/finotti/local/bash_completion/bash_completion.d/openoffice",
O_RDONLY|O_LARGEFILE) = 3
open("/home/finotti/local/bash_completion/bash_completion.d/pon",
O_RDONLY|O_LARGEFILE) = 3
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
open("/home/finotti/local/bash_completion/bash_completion.d/wajig",
O_RDONLY|O_LARGEFILE) = 3
open("/dev/null", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
X
> for example (calling bash with a command so it doesn't open an interactive
> session); or, even more interesting perhaps,
>
> strace -echdir bash -c "echo 'X'"
babbage[~]% strace -echdir bash -c "echo 'X'"
--- SIGCHLD (Child exited) @ 0 (0) ---
chdir("/home/finotti") = 0
--- SIGCHLD (Child exited) @ 0 (0) ---
--- SIGCHLD (Child exited) @ 0 (0) ---
--- SIGCHLD (Child exited) @ 0 (0) ---
--- SIGCHLD (Child exited) @ 0 (0) ---
--- SIGCHLD (Child exited) @ 0 (0) ---
X
I guess there it is...
I commented out the lines:
# Clean up stupid automounter directory
# case $PWD in
# $AUTOHOME*) cd $HOME${PWD#$AUTOHOME} ;;
# esac
and now it works...
babbage[~/tmp]% strace -echdir bash -c "echo 'X'"
--- SIGCHLD (Child exited) @ 0 (0) ---
--- SIGCHLD (Child exited) @ 0 (0) ---
--- SIGCHLD (Child exited) @ 0 (0) ---
--- SIGCHLD (Child exited) @ 0 (0) ---
--- SIGCHLD (Child exited) @ 0 (0) ---
--- SIGCHLD (Child exited) @ 0 (0) ---
X
babbage[~/tmp]% test.sh
/home/finotti/tmp
Is there a way to tell the script NOT to read .bashrc?
Thanks,
Luis
Reply to: