吹く

吹く

以下のように文字列を含む変数があります。

name=@col1, zip_cd=@col2, district=@col3, city=@col4

列のリストが大きくなる可能性があります。

次の出力が必要です

@col1,@col2,@col3,@col4

ベストアンサー1

唯一の目標が変数のすべての値(つまり文字通り@col1,@col2,@col3,@col4)を印刷することである場合は、配列を使用してください。

$ array=($name $zip_cd $district $city)

出力:

$ oIFS="$IFS" # save IFS for later
$ IFS=","
$ echo ${array[*]}
@col1,@col2,@col3,@col4
$ IFS="$oIFS"`enter code here`

列を変数にロードするには、以下を印刷します。

$ line="foo bar qaz qux"
$ oIFS="$IFS" # save IFS for later
$ IFS=" " # space, if $line has spaces/tabs, convert them into single spaces below
$ line=`sed 's/\s\+/ / <<< $line`
$ array=($line)
$ IFS="," # for display
$ echo ${array[*]}
foo,bar,qaz,qux

おすすめ記事