• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to cd to a path in shell script

 
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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')
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A pretty sneaky bug! I'm giving you a cow for posting your solution here.
 
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic