João João - 9 months ago 39
Bash Question

Hide output of cat command

I have this line of code which I would like to hide its output.

Vrs=$(cat $(echo $line | awk -F"-" '{print "/var/AS-"$2"-"toupper($3)"-"$4}') | grep "YES" | cut -d":" -f5)

I have tried to include
&> /dev/null
at the end of the line but it doesn't work.
Does anyone know how to do this?


You could rephrase the statement to

Vrs=$(echo "$line" | awk -F"-" '{print "/var/AS-"$2"-"toupper($3)"-"$4}' | grep "YES" | cut -d":" -f5)

This does the same thing. In the command is successful, you would get the result stored in Vrs. No output would be shown in the stdout. However, if you expect errors, you could do :

Vrs=$(echo "$line" | awk -F"-" '{print "/var/AS-"$2"-"toupper($3)"-"$4}' | grep "YES" | cut -d":" -f5 2>/dev/null)

This will suppress the errors and give you an empty $Vrs


I have double quoted $line to prevent globbing and word splitting.