[colug-432] Argument Quoting in BASH
jep200404 at columbus.rr.com
jep200404 at columbus.rr.com
Wed Apr 15 10:22:26 EDT 2015
On Wed, 15 Apr 2015 09:51:48 -0400, zach villers <zachvatwork at gmail.com> wrote:
> Is there a difference between;
>
> ls -l | grep ^...s
>
> AND
>
> ls -l | grep "^...s"
>
> *trying to find files with setuid permission*
>
> A trainer told me using quotes with the grep statement was necessary,
> but it doesn't seem to be.
That depends on what is inside the quotes.
There is no difference in this case
with the bash shell that I'm using.
show[zach at colug ~]$ showargs ^...s
There are 1 arguments
/home/jep/bin/showargs '^...s'
[zach at colug ~]$ showargs "^...s"
There are 1 arguments
/home/jep/bin/showargs '^...s'
[zach at colug ~]$ cat ~/bin/showargs
echo "There are $# arguments"
echo -n "$0"
i=1
while [ $# -ne 0 ] ; do
echo -n " '$1'"
i=`expr $i + 1`
shift
done
echo
[zach at colug ~]$
Study difference between using no quotes, single quotes,
double quotes, and graves (aka "back ticks").
It is important to understand those differences.
[zach at colug ~]$ f='hello world'
[zach at colug ~]$ showargs echo spam $f eggs
There are 5 arguments
/home/jep/bin/showargs 'echo' 'spam' 'hello' 'world' 'eggs'
[zach at colug ~]$ showargs "echo spam $f eggs"
There are 1 arguments
/home/jep/bin/showargs 'echo spam hello world eggs'
[zach at colug ~]$ showargs 'echo spam $f eggs'
There are 1 arguments
/home/jep/bin/showargs 'echo spam $f eggs'
[zach at colug ~]$ showargs `echo spam $f eggs`
There are 4 arguments
/home/jep/bin/showargs 'spam' 'hello' 'world' 'eggs'
[zach at colug ~]$
By the way, I usually enclose my regular expression for grep
and commands for sed with single quotes, not double quotes.
More information about the colug-432
mailing list