Shell script help
Kelly Dunlop
kelly at xyzzy.org.uk
Wed Oct 15 14:58:42 UTC 2014
On Wed, Oct 15, 2014 at 03:43:38PM +0100, Colin Law wrote:
> This is not strictly a Ubuntu issue but I hope someone will take pity
> on me. I am trying to write a shell script (it is in ash rather than
> bash but I don't think that is an issue here) that is given a
> parameter that is a partial directory name and may have spaces in it.
> I will call it with something like
>
> myscript "dir name"
>
> In the script I want to do something like
> for f in /some/path/$1/*.txt
> do
> blah blah
> done
>
> but I can't work out out how to quote it so that it keeps the words of
> the parameter together but still expands the glob. Google has failed
> to help me to find the right incantation to make it work.
Colin,
Just put the quotes round the part you don't want it to change ie:
for f in /some/path/"$1"/*.txt
I tried calling this script as myscript "dir name":
#!/bin/bash
echo /tmp/"$1"/*.txt
with a directory called /tmp/dir name containing one.txt, two.txt and three.txt
and it gives:
/tmp/dir name/one.txt /tmp/dir name/three.txt /tmp/dir name/two.txt
so it works on bash. Can't test it on ash because I don't have it installed.
HTH
Kelly
>
> Any help would be much appreciated.
>
> Cheers
>
> Colin
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
--
Kelly Dunlop
kelly at xyzzy.org.uk
More information about the ubuntu-users
mailing list