Jump to content

Shell script problems.


  • Please log in to reply
1 reply to this topic

#1
Jadar

Jadar

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 119 posts
  • Gender:Male
  • Location:Unites States
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!

#2
Airr

Airr

    InsanelyMac Protégé

  • Members
  • Pip
  • 17 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!


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

A.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy