How do the environments of a standard Terminal command-line and a bash script differ?
Posted
by
fred.bear
on Ask Ubuntu
See other posts from Ask Ubuntu
or by fred.bear
Published on 2011-01-10T08:41:07Z
Indexed on
2011/01/10
8:58 UTC
Read the original article
Hit count: 411
I know there is something different about the environment of the Terminal command-line and the environment in a bash script, but I don't know what that difference is...
Here is the example which finally led me to ask this quesiton; it may flush out some of the differences.
I am trying to strip leading '0's from a number, with this command.
var="000123"; var="${var##+(0)}" ; echo $var
When I run this command from the Terminal's command-line, I get: 123
However, when I run it from within a script, it doesn't work; I get: 000123
I'm using Ubuntu 10.04, and tried all the following with the sam results:
- GNOME Terminal 2.30.2
- Konsole 2.4.5
- #!/bin/bash
- #!/bin/sh
What is causing this difference?
Even if some upgrade will make it work in scripts...
I am trying to find out the what and why,
so in future, I'll know what to look out for .
© Ask Ubuntu or respective owner