Results 1 to 2 of 2
Hi
I was working a unix shell and created a file using
touch "Hello! It's \$s"
it worked perfect but when i tried to run the same command on the ...
- 02-11-2008 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 1
touch command help
Hi
I was working a unix shell and created a file using
touch "Hello! It's \$s"
it worked perfect but when i tried to run the same command on the linux terminal it returned
s is undefined variable
Please Help ^_^
- 02-11-2008 #2Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
This highly depends on the shell you are using. In bash, doing this:
Will create a file called, textually: "Hello! It's $s".Code:touch "Hello! It's \$s"
And this:
Will create a file called "Hello! It's " + "<the contents of the environment variable 's'". If $s is not defined then the empty string (nothing) will be added to the end of the original string, so the file will be called "Hello! It's ". And nothing more.Code:touch "Hello! It's $s"
So, bash will not complain, even if $s is empty or not defined. Other shells might behave differently, but we can't help without knowing what shell are you using, since different shells might have different ways to scape variables and slightly different rules about this. Note that the shell you run when launching a bash script might be influenced by the first line of your script (for example, if you use something like #!/bin/bash). So, it is not necesarily the same shell you are using on regular command line. You can view the active shell on the $SHELL variable, on both command line or from a given script.


Reply With Quote
