Skip to content

Instantly share code, notes, and snippets.

@greymd
Last active May 4, 2017 06:44
Show Gist options
  • Save greymd/93f3f06e98d0158f5dd570618b6115d2 to your computer and use it in GitHub Desktop.
Save greymd/93f3f06e98d0158f5dd570618b6115d2 to your computer and use it in GitHub Desktop.
bash: IFSと配列の[*]の挙動
$ bash --version
GNU bash, version 4.3.46(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ arr=("aa" "bb" "cc")
$ export IFS=@

クオートで囲まないとIFSは使われない

$ echo ${arr[*]}
aa bb cc

$ echo "${arr[*]}"
aa@bb@cc

exportしないと変わらない

$ IFS="-" echo "${arr[*]}"
aa@bb@cc

$ export IFS="-"; echo "${arr[*]}"
aa-bb-cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment