Shell script question
#1
Scooby Regular
Thread Starter
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes
on
0 Posts
Shell script question
Afternoon/Evening,
A question for those scripting types out there.
I want to have a shell script that I can pass a path to and then have add something to that path and perform an action with it. For example the command would be:
$ ./myscript /Volumes/Mac\ OS\ X/
The script would do the following:
Now, I can issue the command as mentioned above, but it tells me that the path /Volumes/Mac does not exist, so I'm guessing it's not correctly parsing the spaces in the volume name.
What am I doing wrong, and how do I get it to work?
Thanks in advance
A question for those scripting types out there.
I want to have a shell script that I can pass a path to and then have add something to that path and perform an action with it. For example the command would be:
$ ./myscript /Volumes/Mac\ OS\ X/
The script would do the following:
Code:
#!/bin/sh rm -rf "${1}/Library/NameOfFolder/" rm -rf "${1}/Library/StartupItems/AnotherFolder/"
What am I doing wrong, and how do I get it to work?
Thanks in advance
#2
You need to put an if statement in to check.
Something on the lines of:
F1="${1}/Library/NameOfFolder/"
F2="${1}/Library/StartupItems/AnotherFolder/"
if [ -d ${F1} ]
then
rm ${F1}
else
echo " ${F1} not found!"
fi
if [ -d ${F2} ]
then
rm -rf ${F2}
else
echo "${F2} not found !"
fi
A breakdown of this:
declare variables F1 & F2
If -d (directroy) exists then remove
This is NOT tested as my RS6000 isn't powered up at the moment to test this little code. So worth testing 1st!
Something on the lines of:
F1="${1}/Library/NameOfFolder/"
F2="${1}/Library/StartupItems/AnotherFolder/"
if [ -d ${F1} ]
then
rm ${F1}
else
echo " ${F1} not found!"
fi
if [ -d ${F2} ]
then
rm -rf ${F2}
else
echo "${F2} not found !"
fi
A breakdown of this:
declare variables F1 & F2
If -d (directroy) exists then remove
This is NOT tested as my RS6000 isn't powered up at the moment to test this little code. So worth testing 1st!
#3
Scooby Regular
Thread Starter
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes
on
0 Posts
Should have mentioned, the path /Volumes/Mac\ OS\ X/ does exist. I think the problem is due to the spaces in the "Mac OS X" bit of ther path name.
Guessing I need to somehow encode them, any ideas how?
Guessing I need to somehow encode them, any ideas how?
#4
Scooby Regular
Join Date: Sep 2001
Location: Kingston ( Surrey, not Jamaica )
Posts: 4,670
Likes: 0
Received 0 Likes
on
0 Posts
and all your backslashes that will need escaping ....
could use 'eval'
$ x="etcha\ sketch"
$ eval cd $x
export $basedir="/path/to/space in/here"
echo $basedir fails
echo "$basedir" works.....
I can't test it all as I don't have access to macs.....give it a whirl...
could use 'eval'
$ x="etcha\ sketch"
$ eval cd $x
export $basedir="/path/to/space in/here"
echo $basedir fails
echo "$basedir" works.....
I can't test it all as I don't have access to macs.....give it a whirl...
#6
You need to put the args in double quotes when you call it e.g.
$ ./myscript "/Volumes/Mac\ OS\ X/"
...then it will be treated as one arg. Otherwise you could concatenate it in your script like...
var=`echo $1 $2 $3`
$ ./myscript "/Volumes/Mac\ OS\ X/"
...then it will be treated as one arg. Otherwise you could concatenate it in your script like...
var=`echo $1 $2 $3`
Thread
Thread Starter
Forum
Replies
Last Post
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM