У меня есть переменная оболочки
str= this 'is shell' script 'to learn'
Я хочу заменить первое вхождение ' на " ' и второе вхождение ' на ' " и т. Д.
'
" '
' "
наконец
str= this "'is shell'" script "'to learn'"
Попробуйте это
$ str=" this 'is shell' script 'to learn' " $ echo $str this 'is shell' script 'to learn' $ perl -pe 's/\x27/sprintf("%s",++$i%2==0? "\"\x27" : "\x27\"")/ge' <<< "$str" this '"is shell"' script '"to learn"' $
echo $str | perl -pe "s|'(.*?)'|\"'\1'\"|g"