Active Topics

 


Reply
Thread Tools
FRuMMaGe's Avatar
Posts: 330 | Thanked: 483 times | Joined on Dec 2010 @ Norwich, UK
#1
I've come across a ridiculously infuriating problem.

I'm trying to load a simple bash script that cd's to a directory and executes a function, but whenever I sh the script, it ALWAYS tells me "can't cd /whatever/directory" (obviously this is not the actual directory)

For debugging purposes, I have set the directory name to things that DEFINITELY exist, such as /home/user/MyDocs/

I have run the command by itself in xterm with no problems, but it gets picky when I run it from a script.

I have chmod +x it and everything is as it should be. What the hell is wrong?
__________________
OMNOM: Pacman-like game now in extras-devel

fAircrack (Aircrack GUI): Point-and-click pwnage for your N900
Now with John the Ripper integration
 
Posts: 992 | Thanked: 738 times | Joined on Jun 2010 @ Low Earth Orbit
#2
Show some example code that illustrates your problem?
 

The Following User Says Thank You to kureyon For This Useful Post:
Posts: 162 | Thanked: 25 times | Joined on Dec 2009
#3
wildly speculating... cd is not a program but part of the shell, isn't it? Does it make a difference if you execute your script using 'sh scriptname' or by chmodding it tox x and then execute it directly?

paai
 

The Following User Says Thank You to paai For This Useful Post:
Posts: 28 | Thanked: 14 times | Joined on Sep 2010
#4
another speculation...
is the script in fat partition? is so, try putting it in ext2 partition ( /home/user/scripts or whatever you want...)
 

The Following User Says Thank You to littlebadger For This Useful Post:
FRuMMaGe's Avatar
Posts: 330 | Thanked: 483 times | Joined on Dec 2010 @ Norwich, UK
#5
The script is basically just:

cd /home/user/MyDocs/
sh config.sh

Tried chmodding it and running it directly but it just says "permission denied". Its now in my opt diretory

The commands run fine when copied to the terminal, that's why this is so irritating
__________________
OMNOM: Pacman-like game now in extras-devel

fAircrack (Aircrack GUI): Point-and-click pwnage for your N900
Now with John the Ripper integration
 
Posts: 6 | Thanked: 7 times | Joined on Jan 2010
#6
Are line endings in the script correct? If you created the script on windows, chances are lines end on CR-LF instead of LF only, and the shell will include that CR character at the end of the command it parses. I'm pretty sure the directory you want to cd to doesn't have a CR character in its name.
 
FRuMMaGe's Avatar
Posts: 330 | Thanked: 483 times | Joined on Dec 2010 @ Norwich, UK
#7
Originally Posted by fgevaerts View Post
Are line endings in the script correct? If you created the script on windows, chances are lines end on CR-LF instead of LF only, and the shell will include that CR character at the end of the command it parses. I'm pretty sure the directory you want to cd to doesn't have a CR character in its name.
Nope. made it on leafpad with my n900
__________________
OMNOM: Pacman-like game now in extras-devel

fAircrack (Aircrack GUI): Point-and-click pwnage for your N900
Now with John the Ripper integration
 
Posts: 162 | Thanked: 25 times | Joined on Dec 2009
#8
I think your script works just fine :-) Considerthe following variant:

cd /home/user/MyDocs/
pwd

where pwd of course displays the current working directory.

You will see that the script prints '/home/user/MyDocs/', so it executes 'cd' all right.. The unexpected part is that after execution, control returns to the original situation.

Paai
 
Posts: 6 | Thanked: 7 times | Joined on Jan 2010
#9
Originally Posted by paai View Post
it executes 'cd' all right..
It wouldn't say "can't cd to /whatever/directory" then.

FRuMMaGe: Can you run "od -c yourscript.sh", and check that there are indeed only \n characters for line ending, and no \r?

The "can't cd to /whatever/directory" error is printed if you do have this wrong, which is why I wouldn't rule out this possibility without seriously checking.

Last edited by fgevaerts; 2011-01-04 at 16:11.
 

The Following 2 Users Say Thank You to fgevaerts For This Useful Post:
FRuMMaGe's Avatar
Posts: 330 | Thanked: 483 times | Joined on Dec 2010 @ Norwich, UK
#10
Originally Posted by fgevaerts View Post
It wouldn't say "can't cd to /whatever/directory" then.

FRuMMaGe: Can you run "od -c yourscript.sh", and check that there are indeed only \n characters for line ending, and no \r?

The "can't cd to /whatever/directory" error is printed if you do have this wrong, which is why I wouldn't rule out this possibility without seriously checking.
I ran your command and it does indeed end in an /r then an /n

How do I correct this?
__________________
OMNOM: Pacman-like game now in extras-devel

fAircrack (Aircrack GUI): Point-and-click pwnage for your N900
Now with John the Ripper integration
 
Reply


 
Forum Jump


All times are GMT. The time now is 07:34.