Jump to content

Shell script problems.


2 posts in this topic

Recommended Posts

Hey guys. I am making a shell script to make a folder with space and a timestamp in its name. Then it changes to it. I do this like this:

 

date=`date +%Y-%m-%d-%H:%M:%S`
folder="/folder\ withspace-$date"
mkdir $folder
cd $folder

 

This would, to me, make sense to work. That is not the case here, because when I try this in Terminal to test I get this:

 

$ date=`date +%Y-%m-%d-%H:%M:%S`
$ folder="/folder\ withspace-$date"
$ sudo mkdir $folder
Password:
$ ls /
[other folders]
folder\

 

So I am really stumped because it also makes another directory in my current directory. What am I doing wrong? Thanks!

Link to comment
Share on other sites

  • 3 weeks later...
Hey guys. I am making a shell script to make a folder with space and a timestamp in its name. Then it changes to it. I do this like this:

 

date=`date +%Y-%m-%d-%H:%M:%S`
  folder="/folder\ withspace-$date"
  mkdir $folder
  cd $folder

 

This would, to me, make sense to work. That is not the case here, because when I try this in Terminal to test I get this:

 

$ date=`date +%Y-%m-%d-%H:%M:%S`
  $ folder="/folder\ withspace-$date"
  $ sudo mkdir $folder
  Password:
  $ ls /
  [other folders]
  folder\

 

So I am really stumped because it also makes another directory in my current directory. What am I doing wrong? Thanks!

 

Try removing the "\" from "/folder\ withspace-$date", and encasing the $folder variable in quotes like "$folder".

 

A.

Link to comment
Share on other sites

 Share

×
×
  • Create New...