ifs

What is the exact meaning of IFS=$'\n'?

时间秒杀一切 提交于 2019-11-26 06:11:45
问题 If the following example, which sets the IFS environment variable to a line feed character... IFS=$\'\\n\' What does the dollar sign mean exactly ? What does it do in this specific case? Where can I read more on this specific usage (Google doesn\'t allow special characters in searches and I don\'t know what to look for otherwise)? I know what the IFS environment variable is, and what the \\n character is (line feed), but why not just use the following form: IFS=\"\\n\" (which does not work)?

Trying to split a string into two variables

你。 提交于 2019-11-26 03:36:15
问题 I\'m trying to split a string into two variables (without having to use a while loop): var=\"hello:world\" IFS=\':\' read var1 var2 <<< $var echo \"var1: $var1\" echo \"var2: $var2\" but i\'m not getting the desired result: var1: \'hello world\' var2: \'\' Could anybody please explain if it\'s possible to do it this way (or similar way)? 回答1: This is a bug in Bash 4.2. See chepner's answer for a proper explanation. It is about quotes. Use: IFS=':' read var1 var2 <<< "$var" ^ ^ instead of IFS=