I need to assign a command to a variable and execute it with variable in linux bash. The command executes fine from command line but not from the variable because of multiple quotes. I hope backslash should be used for multiple quotes to avoid the error. Please help with the correct format.
**Code:**
parm="cat file|awk '$1>0 && $1="abc" {print f $0} {f=$0 ORS}'"
eval "$parm"
**Contents:**
abc
123
efg
456
**Error:**
awk: cmd. line:1: >0 && =abc {print f bash} {f=bash ORS}
awk: cmd. line:1: ^ syntax error
Thanks in advance!
Asked by Kishan
(113 rep)
Jan 16, 2025, 05:05 AM
Last activity: Jan 16, 2025, 08:05 AM
Last activity: Jan 16, 2025, 08:05 AM