Hey can anyone help me to solve syntax error on creation of alias
.I am new to bash so i am not aware of any restriction in use of alias
command
Every time i run this alias
command
JavaScript
x
alias user='responseVar=$(curl -XGET link) && echo ${responseVar} | jq '.offsets[] | " (.topic) (.offset) (.logSize) "' | awk 'NR>1{arr[$2]=arr[$2]+($4-$3)} END{for (a in arr) print a"="arr[a]}''
I get this error.
JavaScript
bash: syntax error near unexpected token `('
Advertisement
Answer
Avoid using alias
(they’re only allowed in interactive shells) and define a simple function instead to do
JavaScript
doSomething() {
curl -XGET link | jq '.offsets[] | " (.topic) (.offset) (.logSize) "' |
awk 'NR>1{arr[$2]=arr[$2]+($4-$3)} END{for (a in arr) print a"="arr[a]}'
}
and defined in any of your startup configuration files(e.g. .bashrc
for instance) and launch and new shell and do just
JavaScript
doSomething