I am assigning a variable to echo command which generates a random number.
For eg: n=$(echo $(( (RANDOM%6) +1))
. I have to grep this variable in /etc/passwd
.
So, my syntax reads like:
n=$(echo $(( (RANDOM%6) +1)) | grep "$n" /etc/passwd
But I get the entire file content(/etc/passwd
) as output. I do not know where the syntax is wrong.
It is important I get the output in one line only.
$(echo
part is pointless;n=$(( (RANDOM%6) +1))
is sufficient. Hint 3: A pipe|
creates child processes that run essentially in parallel. Do you think it makes sense to execute these two commands in parallel? – Uwe Mar 9 '15 at 19:54|
by;
. – Cyrus Mar 9 '15 at 20:06