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
Re: How to retrieve a variable in UNIX
Must be
without "$" to val.
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?
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
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.