0

What is the difference between

function searchGitAliases() {
   found=$(cat ~/aliases/.gitAliases| sed -e 's/alias //g' -e 's/function //g' -e 's/=.*//g' -e 's/()//g' -e 's/{.*//g' | sort -r -u | fzf) && eval ${found}
}

and

function searchGitAliases(){ found=$(cat ~/aliases/.gitAliases | sed -e 's/alias //g' -e 's/function //g' -e 's/=.*//g' -e 's/()//g' -e 's/{.*//g' | sort -r -u | fzf) && eval ${found} }

The first one works without problems, the second one does not.

When I run it in the shell it expects another closing bracket

function searchGitAliases(){ found=$(cat ~/aliases/.gitAliases | sed -e 's/alias //g' -e 's/function //g' -e 's/=.*//g' -e 's/()//g' -e 's/{.*//g' | sort -r -u | fzf) && eval ${found} }
> }

I cant see any difference between them except that the first one is on a different line while the second one has the body on the same line. Does this matter in bash?

Note: Both work in zsh.

leoOrion
  • 1,833
  • 2
  • 26
  • 52
  • There are multiple unrelated problems with your function. I'm afraid of trying to figure out what it does. If you can't avoid a [useless `cat`](/questions/11710552/useless-use-of-cat) I'd find it hard to believe that your use oif `eval` is secure. – tripleee Jan 09 '20 at 14:26
  • Thanks for the redirect to the similar question. I have some doubts on the useless cat though.Why would eval become insecure? I went through the link you provided and cant find a reason how it would affect eval. Also while cat is uneccasarry, does it cause any disadvantage? – leoOrion Jan 09 '20 at 14:55
  • The useless `cat` is unrelated to your use of `eval` but a bad smell. You should easily find a wealth of information about why `eval` is insecure in most languages which provide this feature. – tripleee Jan 09 '20 at 14:57
  • Ok. Thanks. Does unnecessary use of cat cause a disadvantage? – leoOrion Jan 09 '20 at 14:59
  • The linked question contains an answer which outlines the overhead. It's rather small for a single file, but nevertheless an inconvenience which would be easy to avoid. – tripleee Jan 09 '20 at 15:02

0 Answers0