I have to do an alias called for example "longest" for this script:
data=""; len=0; line=""; while [[ $line != "quit" ]]; do read line; [[ $line != "quit" ]] && [[ ${#line} -gt len ]] && len=${#line} data=$line; done; echo $len; echo $data 1>2
Its job is simply reading words or phrases and counting the characters.
I put the script inside quotes like this:
alias longest="...script..."
but it doesn't work and I don't know why. Can anyone explain to me why? A possible solution?
alias longest=' ... '1>&2(or just>&2) rather than1>2. Also, there are a bunch of things in there that really should be double-quoted to avoid parsing weirdness. Finally, I'd recommend stopping on end-of-file as well as/instead of when getting "quit" (you could usewhile read line && [[ $line != "quit" ]]; do ...to check for either).