Re: Problem with positional output

"[email protected] [sed-users]" <[email protected]> 28 Nov 2016 05:25:28 -0800
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
 

---In [email protected], <linux4michelle@...> wrote :
 > Not realy, because I need to seperate theoutput of "zenity" which return> VAL1|VAL2|VAL3
 
> LINK="$(echo ${RETURN} |sed 's!\(.*\)|\(.*\)|\(.*\)!\1!')"
> FNAME="$(echo ${RETURN} |sed 's!\(.*\)|\(.*\)|\(.*\)!\2!')"
> DIR="$(echo ${RETURN} |sed 's!\(.*\)|\(.*\)|\(.*\)!\3!')"
 

 There are many issues with the above:
   1. Running a command multiple times.
   2. echo will behave incorrectly for certain values of $RETURN
   3. $RETURN might contain globbing chars which might play truant since $RETURN is left unquoted.
   4. if any of the VALs happen to contain trailing newlines then they shall be lost.
   5. There is no need to quote the var=$(...) construct coz it's superfluous.
 

 

 We can do something like the following:
 

     set -f; IFS=\|; set -- $RETURN
     case ${3++} in ?) LINK=$1  FNAME=$2   DIR=$3;; 

     '' ) echo >&2 "Error";; esac
 

 N.B.: You should restore the IFS and set -f settings afterwards.



[Non-text portions of this message have been removed]