I'm trying to replace some codes with bash function to reuse it. So my previous codes are:
#!/bin/bash
set aline=" dsfsdf | fsdfff | yuhfd "
set line_parsed=`echo $aline | tr '|' "\n"`
echo ${line_parsed[1]}
Which outputs dsfsdf
.
Now, if I'm trying to put the sentence in a function, I cannot get it right:
#!/bin/bash
parseLine ()
{
set line_parsed=`$echo $1 | tr '|' "\n"`
echo ${line_parsed[1]}
}
set aline=" dsfsdf | fsdfff | yuhfd "
parseLine $aline
Is there a syntax error?
$echo
? ShellSheck is your friend. shellcheck.net