• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to cd to a path in shell script  RSS feed

 
Russy Bond
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 1) a properties file and 2) a shell script.

In my shell script, I am trying to call a property, P4_PATH (defined in the properties file).
If I try echo $P4_PATH, it works fine and prints the path (/Users/Russy/Perforce/iOS_develop).

Issue: If I try, cd $P4_PATH
I get “: No such file or directory: /Users/Russy/Perforce/iOS_develop

Can someone please let me know what could be going wrong?

The path is a valid one. If I manually cd to that path, it will work fine.

Thanks,
Russy
 
Russy Bond
Greenhorn
Posts: 12
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved it. The path contains a carriage return. So, the right way to fix it would be
cd $(echo $P4_PATH | tr -d '\r')
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A pretty sneaky bug! I'm giving you a cow for posting your solution here.
 
Andrew Polansky
Ranch Hand
Posts: 310
18
Linux MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Other solution would be to reformat your file. It looks it is in the DOS format, where every line ends with \r\n. The Unix format ends only with \n. You can use dos2unix utility to do that, or you can simply open the file in any editor and replace all \r with no character.

As a tip, it is always good to use quote marks when accessing paths from variables. With quotes, your script will not break if the path contains ie. a space.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!