I want to put the output of command in bash variable and then further use that variable in other command
Suppose i want something like this
ls | $(variable) |awk '/$variable/{print "here"}'
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.
You can try:
Note 1:
/$variable/is surrounded by double quotes, otherwise it won’t be replaced by output of command.Note 2: The above command may fail since the output of
lsmay contains “/” or newline, which will break theawkcommand. You may changelsto something likels | tr '\n' ' ' | tr -d '/' | sed 's/ *$//g'(replace all newlines with spaces; delete all slashes; remove the trailing whitespace), depending on your goal.Note 3: to avoid variable assignment polluting the current shell’s environment, you can wrap the above command by parentheses, i.e.
(variable=$(some_command); awk "/$variable/"'{print "here"}')