shell - Why zenity color selection piping to sed breaks the code? -
i trying use sed convert 12 digit hex code returned zenity's --color-selection dialogue 6 digit hex code. example: #dfe251a951a9 #df5151. use sed in following code breaks whole script, , when select "select" or "cancel" buttons dont respective echo! what's problem?
before using sed: works nice 12 digit hex code.
#!/bin/bash color=$(zenity --color-selection) if [[ $? == 0 ]] echo "you selected $color." else [[ $? == 1 ]] echo "no color selected." fi
after using sed: when hit select button 6 digit hex code when hit cancel dont "no color selected", echoes "you selected ."
#!/bin/bash color=$(zenity --color-selection | sed 's/\(#\?..\)../\1/g') if [[ $? == 0 ]] echo "you selected $color." else [[ $? == 1 ]] echo "no color selected." fi
after
color=$(zenity --color-selection | sed 's/\(#\?..\)../\1/g')
$?
exit status of sed
(not zenity
)1, 0. use
#!/bin/bash color=$(zenity --color-selection) # $? exit status of zenity if [[ $? == 0 ]] # process sed if necessary. color=$(echo "$color" | sed 's/\(#\?..\)../\1/g') echo "you selected $color" else echo "no color selected." fi
note, way, version of zenity
(3.16.2) not return hexadecimal code of form rgb(12,34,56)
. have not investigated when or why change happened, may not wise rely on particular format.
1 more precisely: it's exit status of subshell spawned $()
, forwards exit status of last command ran: sed
call.
Comments
Post a Comment