I am trying to put the content of a file into a variable, this is my code:
var=cut -d@ -f1 tmp2
I also tried with piping, let var and etc.
How do I make it work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try this
The
$( .. )is call command substitution. Cmd substitution can also be performed with ` … ` pairs per @JanVorcak’s solution but that syntax is considered deprecated, unless you’re expecting to use old vendor Unix like Solaris WITH the bourne shell. Incidentally, you say that var now equals ‘cat file.txt’. You must be using the wrong char, most likely the single quote char', instead of the back-quote char “`”.As your title says you’re trying to ‘put the content of a file into a varible’, I’m surrounding the output of cut with ” … “. Now the value of var is the complete output of
cut ....I hope this helps.