How do I escape $# in shell scripting?
Hi,
I've tried to search for this on google and this site's search engine but they all can't recognize these characters so ... I'm trying to test for how many parameters a command line argument is given and I use if [ $# -eq 1 ] then ... anyway when I do this in vi & bash they don't recognize everything after #. Is there some way to escape this? Thanks. |
The following works for me
Code:
#!/bin/sh Code:
[jh@e128 jh]$ ./test.sh Jamie... |
Don't know why it doesn't work. It works for me...
Are you sure the $# is the problem? Usually I always quote the variables in my tests, even though it's not always necessary. I just saves me some hassle whenever it does matter... Code:
if [ "$#" -eq 1 ]; then |
vi will see the # as a comment. It will still run as a shell script. I see this all the time in my scripts editing them in vi
|
All times are GMT -5. The time now is 02:05 PM. |