help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] variable assign preceding script


From: Greg Wooledge
Subject: Re: [Help-bash] variable assign preceding script
Date: Thu, 2 Jun 2016 10:51:55 -0400
User-agent: Mutt/1.4.2.3i

On Thu, Jun 02, 2016 at 10:41:02PM +0800, Wu Shuangrong wrote:
> I have a script and now i want to change the environment variable IFS to null 
> value for all of the commands contained within the script, so will the 
> following form of calling script work?
> 
> $> IFS= myscript arg1 arg2 arg3

No, it will not.  IFS is special.  Bash ignores the value of IFS from
the environment and initializes IFS to $' \t\n' in order to avoid having
scripts fail in horrible ways.

imadev:~$ IFS=x bash -c 'printf "%q\n" "$IFS"'
$' \t\n'

> Will IFS changing just affect the first command in the script file?

It will not do anything at all.

> If this is the case, how should I do to achieve my goal?

Fix the bugs in your script that make you think overriding IFS is the
only way forward.  Usually this means quoting correctly.  See
http://mywiki.wooledge.org/BashPitfalls for specific suggestions.
See http://mywiki.wooledge.org/Quotes for a discussion of how to quote.
See http://shellcheck.net/ for an automated script checker.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]