Jump to content
InsanelyMac Forum
  • Announcements

    • Allan

      Solution to create a topic or post.   04/24/2018

      Hello guys. The majority of you are having issues to create a topic or post here. This are a problem with our current theme InsanelyMac.  Now the theme will be the Default IPS. Sorry for any inconvenience.
Sign in to follow this  
Jadar

Shell script problems.

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!

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.



×