Try this:
system("cd /somedir"
hi,
Is it possible to change current directory in bash from perl?
I do
`cd /somedir`
and is says that the directory doesn't exist.
Try this:
system("cd /somedir"
neither of those will work, cd isn't an actually command it's built into the shell.
Are you trying to change the directory for the perl script or for the bash prompt that called the perl script?
You can change it for the perl script with chdir("/foo"
then open(A, "bar"will open bar in /foo
so `cd foo` wouldn't work?
[quote author=gorn link=board=9;threadid=8780;start=0#msg79289 date=1078160901]
neither of those will work, cd isn't an actually command it's built into the shell.
Are you trying to change the directory for the perl script or for the bash prompt that called the perl script?
You can change it for the perl script with chdir("/foo"
then open(A, "bar"will open bar in /foo
[/quote]
couldn't you also use sysopen?
Gorn is right 'cd' is not an actual command.
The objective here is not to open a file but, to just change the directory that bash is in from a perl script.
The reason I'm using perl is because I don't know anything about regular expressions in BASH. Is there an equivilent to 'split' in bash?
thanks,
@shebang the point wasn't open() it was chdir(), it changes the cwd for the process
@blaqb0x even in a bash script if you "cd /" when the bash script quits it won't be in / any longer, it will be in the directory before the script was run, to remedy this source the script rather than run (source foo.sh or . foo.sh) and to split, echo asd-bsd-csd | cut -d- -f2 will print bsd, you could also do a $a=`echo asd-bsd-csd | sed -e 's/-/ /'` and then for i in $a; do echo $i; done
Bookmarks