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

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



Hi!

On Thu, Jan 05, 2006 at 02:25:10PM -0500, 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)
> ----------------

Hm, this is a bit redundant - it's not necessary to wrap pwd into
process substitution and echo the results...

---
#!/bin/bash
pwd
---

should do it.

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"

return? And which files does bash read on startup? (Try

strace -eopen bash -c "echo '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'"


HTH,

Jan

-- 
Jan C. Nordholz
<jckn At gmx net>

Attachment: signature.asc
Description: Digital signature


Reply to: