Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
2 つの単語を含む文字列がありますが、1 つの単語しか含まれていない場合があり、両方の単語を取得する必要があり、2 番目の単語が空の場合は空の文字列が必要です。私は以下を使用しています:
STRING1=`echo $STRING|cut -d' ' -f1` STRING2=`echo $STRING|cut -d' ' -f2`
STRING が 1 つの単語のみの場合、両方の文字列は同じですが、2 番目の画面を空にする必要があります。
なぜ使用しないのですかread:
read
STR='word1 word2' read string1 string2 <<< "$STR" echo "$string1" word1 echo "$string2" word2
今欠けている2番目の単語:
STR='word1' read string1 string2 <<< "$STR" echo "$string1" word1 echo "$string2" | cat -vte $