[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] how to find only the third command is valid?
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] how to find only the third command is valid? |
Date: |
Fri, 5 Feb 2016 08:58:28 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Fri, Feb 05, 2016 at 06:01:24PM +0800, wk wrote:
> address@hidden test]# ./cmd -c "money sho"w
> address@hidden test]# ./cmd -c "money "show
> address@hidden test]# ./cmd -c "money show"
>
> Question:
> I want to only allow case 3 :
> ./cmd -n admin -p admin -c "money show"
There is literally no difference among these commands. They all pass
*exactly* the same arguments, as you have already demonstrated with your
C program.
By the way, you can do the same thing in sh:
#!/bin/sh
printf "%d args:" "$#"
printf " <%s>" "$@"
echo
imadev:~$ args "quotes" """"""are''''$'' fun
3 args: <quotes> <are> <fun>
When the shell parses a command, one of the steps it performs is called
"quote removal". In my example above, the first word the parser sees
is <args>, so that becomes the name of the command. The second word it
sees is <"quotes">, and after quote removal and other expansions (none
of which apply here), the second word becomes <quotes>, and that will
be the first argument of the command. The third word the parser sees is
<""""""are''''$''> which has three different kinds of quoting. After
removing all of those quotes, the word becomes <are> and that is the
second argument of the command. The final word is <fun> and needs no
further processing.
There is no way to differentiate among
./cmd -c "money sho"w
./cmd -c "money "show
./cmd -c "money show"
As far as the shell is concerned, they are all identical. Every one of
them parses the final word as <money show>.
What exactly are you trying to achieve, and WHY?