bash - Escape awk $ in shell function of bashrc -
i have command gets next id of table pool of sql files, trying put command alias in ~/.bashrc using shell function, did not figure out how escape $
gets awk , not replaced bash, here's code in .bashrc
:
function nextval () { grep 'insert \""$1"\"' *.sql | \ awk '{print $6}' | \ cut -c 2- | \ awk -f "," '{print $1}' | \ sort -n | \ tail -n 1 | \ awk '{print $0+1}' } alias nextval=nextval
usage: # nextval tablename
escaping \$
error: awk: backslash not last character on line
. $
not inside double quotes, why bash replacing ?
perhaps part need change this
'insert \""$1"\"'
to
"insert \"$1\""
Comments
Post a Comment