[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [Way OT] "#!/bin/bash" changes working directory



On Thursday 05 January 2006 12:25, Luis Finotti wrote:
> Dear all,
>
> I realize that this should be "way off topic", so sorry about that...
>
> I've been working on a bash script, but when I run something like:
> ---------------
> #!/bin/bash
>
> echo $(pwd)
> ----------------
> I always get $HOME, not the current working directory.  I'd need to
> continue in the working directory from where the script was called to
> work on the files there.  (I'd like it to be portable too, so although
> it seems to work in my home machine running sarge, it doesn't work
> with Fedora or OSX...)

The script you've shown works fine, just the way you want. Nothing in there 
is going to change the working directory. 

For example:

$ pwd
/home/wjl/tmp
$ cat <<EOF >test.sh
#!/bin/bash
echo $(pwd)
EOF
$ chmod a+x test.sh
$ ./test.sh
/home/wjl/tmp

If you think you're having magic changing directories, I think you'll need 
to post more information, like the exact script you're using, and EXACTLY 
how you are running it. =)

-- 
Wesley J. Landaker <wjl@icecavern.net> <xmpp:wjl@icecavern.net>
OpenPGP FP: 4135 2A3B 4726 ACC5 9094  0097 F0A9 8A4C 4CD6 E3D2

Attachment: pgpKmXVECgBZh.pgp
Description: PGP signature


Reply to: