[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Tilde expansion gets automatically disabled in shell scripts
From: |
raj |
Subject: |
Tilde expansion gets automatically disabled in shell scripts |
Date: |
Wed, 25 Jul 2001 14:41:34 +0530 |
Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i386'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-redhat-linux-gnu'
-DCONF_VENDOR='redhat' -DSHELL -DHAVE_CONFIG_H -D_GNU_SOURCE
-D_FILE_OFFSET_BITS=64 -I. -I. -I./include -I./lib -I/usr/include -O2
-march=i386 -mcpu=i686
uname output: Linux powai 2.2.16-22 #1 Tue Aug 22 16:49:06 EDT 2000 i686 unknown
Machine Type: i386-redhat-linux-gnu
Bash Version: 2.04
Patch Level: 11
Release Status: release
Description:
[Detailed description of the problem, suggestion, or complaint.]
Tilde expansion gets automatically disabled when we assign environment
variables to variables inside a shell script (I think)
Specifically consider the following script where I am attempting to
reproduce some functionality of the "which" command
#!/bin/bash
PATH=~:~/bin
for foo in `echo $PATH | /bin/sed 's/^:/.:/
s/::/:.:/g
s/:$/:./
s/:/ /g'`
do
set -x
if test -f $foo/bar
then
echo $foo/bar found
exit
fi
done
Here is the output
+ set -x
+ test -f /home/raj/bar
+ set -x
+ test -f /home/raj/bin/bar
However if I do not assign to PATH inside the script by commenting out the
first line of this script after the shebang line, here is the output:
+ set -x
+ test -f '~/bar'
+ set -x
+ test -f '~/bin/bar'
Notice that the shell is automatically disabling tilde expansion here.
Repeat-By:
[Describe the sequence of events that causes the problem
to occur.]
Fix:
[Description of how to fix the problem. If you don't know a
fix for the problem, don't include this section.]
- Tilde expansion gets automatically disabled in shell scripts,
raj <=