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

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -