Create variable BASH command -
i try customize little bash script special proprose.
i'm confuse bash scripting when come time assigne command variable.
my broken code:
if [ -n "$2" ] top=`| head -n $2` fi awk '{print $17, ">", $19;}' $logs_folder$i | sort -g | uniq -c | sort -r -g $top
so default return line if user specified number, add head command
use array form instead:
if [ -n "$2" ] top=(head -n "$2") else top=(cat) fi awk '{print $17, ">", $19;}' "$logs_folder$i" | sort -g | uniq -c | sort -r -g | "${top[@]}"
and try add more quotes ("").
actually can't save pipe variable , let bash parse normal way when it's expanded can replace command instead (cat).
you use eval it's pretty delicate:
if [ -n "$2" ] top="| head -n \"\$2\"" fi eval "awk '{print $17, \">\", \$19;}' \"\$logs_folder\$i\" | sort -g | uniq -c | sort -r -g $top"
Comments
Post a Comment