Results 1 to 4 of 4
Hi everyone!
I try to get an option in bash and send it to a c program,
like this:
# progName -a "getPacket !MY_IP -> any"
but when I run ...
- 07-10-2007 #1Just Joined!
- Join Date
- Jul 2007
- Posts
- 2
strange behavior of "!" symbol
Hi everyone!
I try to get an option in bash and send it to a c program,
like this:
# progName -a "getPacket !MY_IP -> any"
but when I run it, the "!" symbol replace with some strings
that I don't know where are they come from! and this error occurs:
-bash: event not found
then I check this format:
# progName -a "getPacket \!MY_IP -> any"
but I see that "\" pass to my program, too!
I try to do it with double quote option ("!"MY_IP), but it's not
successfully.
Please tell me how can I pass the "!" symbol to my prog?!
(you can run these commands in bash and see one of strange behavior of "!":
pwd !ls
!pwd ls
It seems that "!" points to a temp memory.)
Thank you in advanced.
- 07-10-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
If you want the output of this command as a parameter for your program:
try something like:Code:getPacket !MY_IP -> any
or:Code:progName -a `getPacket !MY_IP -> any`
RegardsCode:progName -a $(getPacket !MY_IP -> any)
- 07-10-2007 #3
Use single quotes:
What '!' does is it looks for the last command you executed starting with whatever follows '!'. For instance:Code:alex@danu ~ $ echo !hi bash: !hi: event not found alex@danu ~ $ echo "!hi" bash: !hi: event not found alex@danu ~ $ echo '!hi' !hi
You can also use '!!' to repeat the last command:Code:alex@danu ~ $ echo "Hello there" Hello there alex@danu ~ $ !ec echo "Hello there" Hello there
I personally use '!' a lot when dealing with mounting:Code:alex@danu ~ $ echo "Hello there" Hello there alex@danu ~ $ !! echo "Hello there" Hello there
That last command will end up as 'umount /mnt/usb'. A much faster way to do that sort of stuff.Code:mount /mnt/usb # do stuff, not using commands that start with 'mo' u!mo
'!' has some other cool powers. For instance, '!$' is the last argument of the last command:
There's a lot of cool stuff that it does.Code:alex@danu ~ $ vi testfile1 testfile2 2 files to edit alex@danu ~ $ echo !$ echo testfile2 testfile2
Sorry for digressing
.
DISTRO=Arch
Registered Linux User #388732
- 07-11-2007 #4Just Joined!
- Join Date
- Jul 2007
- Posts
- 2
OK! it works correctly! Thanks a lot!


Reply With Quote