unix - Using variables in command line -


i wrote code , works great need use variables instead static numbers scopes 8 , 16

cat /etc/passwd | sed '/^#/d' | sed -n 'n;p' | sed 's/:\(.*\) //g' | sed 's/ /,/g' | sed 's/\(.*\),/\1./' | sort -r | sed 's/*rav://g' | sed "s/:.*//" | rev | sed -n -e '8,16p' | xargs | sed -e 's/ /, /g' | sed '/:[0-9]*$/ ! s/$/./' 

i've changed code

cat /etc/passwd | sed '/^#/d' | sed -n 'n;p' | sed 's/:\(.*\) //g' | sed 's/ /,/g' | sed 's/\(.*\),/\1./' | sort -r | sed 's/*rav://g' | sed "s/:.*//" | rev | sed -n -e '$ft_line1,$ft_line2+p' | xargs | sed -e 's/ /, /g' | sed '/:[0-9]*$/ ! s/$/./' 

but got error

sed: 1: "$ft_line1,$ft_line2p": invalid command code f 

variables enclosed inside single quotes not expanded shell , hence sed command sees argument $ft_line1,$ft_line2p literally. use double quotes , fine:

sed -n -e "$ft_line1,${ft_line2}p" 

see also:


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -