Find the answer to your Linux question:
Results 1 to 4 of 4
Hello. I'm playing around with some shell scripting and I've got a directory call CS005 and I'm trying to write a script to I can locate to the directory really ...
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    13

    Allowing export to take numbers as variables

    Hello. I'm playing around with some shell scripting and I've got a directory call CS005 and I'm trying to write a script to I can locate to the directory really quick and easy.

    export CS005DIR=/home/stud/0/043234/CS005

    Now I get this error

    CS005DIR=/home/stud/0/043234/CS005 No such file or directory.

    This is because I've got numerical values within my variable.

    Is there a way to allow numbers for variable names?
    Thanks

  2. #2
    Just Joined!
    Join Date
    Mar 2007
    Location
    Bogotá, Colombia
    Posts
    39
    It shouldn't be a problem, try to enclose the path in quotes

    try this yourself:

    CS005DIR="/home/stud/0/043234/CS005" ; echo $CS005DIR

    bash should echo your path

  3. #3
    Just Joined!
    Join Date
    Jan 2008
    Posts
    13
    Quote Originally Posted by LSalab View Post
    It shouldn't be a problem, try to enclose the path in quotes

    try this yourself:

    CS005DIR="/home/stud/0/043234/CS005" ; echo $CS005DIR

    bash should echo your path
    Now that seems to work. I've also tried have a value like 2CS005DIR which doesn't work due to it starts with a number (2). Is there a way to allow this?

    Thanks

  4. #4
    Just Joined!
    Join Date
    Mar 2007
    Location
    Bogotá, Colombia
    Posts
    39
    You can use a little trick to make bash accept your variable name, start it with an underscore:

    _2CS005DIR="/your/path" ; echo $_2CS005DIR

    that should work.

Posting Permissions

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