Find the answer to your Linux question:
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 ...
  1. #1
    wsn
    wsn is offline
    Just 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 ^_^

  2. #2
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by wsn View Post
    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 ^_^
    This highly depends on the shell you are using. In bash, doing this:

    Code:
    touch "Hello! It's \$s"
    Will create a file called, textually: "Hello! It's $s".

    And this:

    Code:
    touch "Hello! It's $s"
    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.

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...