Search code examples
shellunixash

How to read a file content in ash into an argument?


I'm trying to read a file which holds a single number in ash shell. The bash way of doing so

ARG=`cat /tmp/tempfile`

doesn't work and I get that ARG doesn't hold anything after this line of code.


Solution

  • try to surround it with quotes to have it not stopped at the first newline:

    ARG="`cat /tmp/tempfile`"
    

    or

    ARG="$(cat /tmp/tempfile)"
    

    or

    read ARG  </tmp/tempfile #only 1st line will be read