c - How can I pipe a string that the user input? -
i need pipe string that's been split individual arguments. example,
cd foo | cat bar.txt
has been parsed , stored array
char *arr[]; arr = {"cd", "foo", "|", "cat", "bar.txt"}
my initial thought traverse array until see pipe , store commands array run it. there way approach this?
yon can use awk :
str="cd foo | cat bar.txt"
command_first=echo $str | awk -f "|" '{print $1}'
command_second=echo $str | awk -f "|" '{print $2}'
eval $command_first
eval $command_second
Comments
Post a Comment