Results 1 to 5 of 5

Thread: How to retrieve a variable in UNIX

  1. #1
    Join Date
    May 2008
    Posts
    551

    How to retrieve a variable in UNIX

    I am on Unix and I have a small problem:

    In sh-mode console, I enter a variable with read and everything works well, I can retrieve it with echo, but in vim, it does not work. When running this script, read the works and I can enter a value, but as soon as this happens a echo, it makes me a line empty. My code:

    Code:
    #!/bin/sh 
    
      echo return a value 
      read $ val 
      echo value is: 
      echo $ val

  2. #2
    Join Date
    Feb 2008
    Posts
    216

    Re: How to retrieve a variable in UNIX

    Must be
    Code:
    read val
    without "$" to val.

  3. #3
    Join Date
    May 2008
    Posts
    551

    Re: How to retrieve a variable in UNIX

    Perfect, so good.

    So another question. Could you explain the mechanism of $ read in the console and not to save for under $ vim.

    If I am not mistaken, the $ in the console is required to declare the variable, right?

  4. #4
    Join Date
    Feb 2008
    Posts
    216

    Re: How to retrieve a variable in UNIX

    It happens exactly the same way in the console:
    Proof:

    Code:
      cedrx @ linux: ~ $ read val 
      25 
      cedr @ linux: ~ $ echo $ val 
      25

  5. #5
    Join Date
    May 2008
    Posts
    551

    Re: How to retrieve a variable in UNIX

    You absolutely right, I just try it in the shell sh and it's good too. In fact I'm in the csh under the console. I'd load because the result is programming in C under Linux. I apologize for my ignorance, but it is not easy to take courses by correspondence after all these years .

    In any case I would like to greatly thank you, it's very nice of your part.

Similar Threads

  1. Retrieve Variable In JSP
    By Amaresh in forum Software Development
    Replies: 4
    Last Post: 10-02-2010, 09:14 PM
  2. Retrieve the result of a DOS command in a variable
    By Kieran in forum Operating Systems
    Replies: 3
    Last Post: 30-01-2010, 06:53 AM
  3. Replies: 2
    Last Post: 28-08-2009, 07:51 PM
  4. Replies: 3
    Last Post: 25-04-2009, 11:34 AM
  5. SUDO under Unix
    By Cecylia in forum Windows Software
    Replies: 4
    Last Post: 24-03-2009, 03:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,390,439.68763 seconds with 16 queries