f



looping inside string containing * / avoid shell expansion

hello,

i'm new to linux shell, i would like to split a string like this one:

TEST="apath/ anotherpath/*.txt"
for d in $TEST
do
    echo "$d"
done

here i wanted to output:

>apath
>anotherpath/*.txt

btw i just can not avoid shell to expand '*.txt' to 'file1.txt',
'file2.txt'; etc.

i think i am missing something around 'TEST' in 'for d in $TEST' but i
have no clues...

best,
0
valia02004
5/8/2004 4:39:49 PM
comp.unix.shell 15484 articles. 2 followers. Post Follow

2 Replies
983 Views

Similar Articles

[PageSpeed] 50

On Sat, 08 May 2004 09:39:49 -0700, Valia wrote:

> hello,
> 
> i'm new to linux shell, i would like to split a string like this one:
> 
> TEST="apath/ anotherpath/*.txt"
> for d in $TEST
> do
>     echo "$d"
> done
> 
> here i wanted to output:
> 
>>apath
>>anotherpath/*.txt
> 
> btw i just can not avoid shell to expand '*.txt' to 'file1.txt',
> 'file2.txt'; etc.
> 
> i think i am missing something around 'TEST' in 'for d in $TEST' but i
> have no clues...
> 
Put double quotes around it.

0
Icarus
5/8/2004 4:52:59 PM
On 2004-05-08, Valia wrote:
> hello,
>
> i'm new to linux shell, i would like to split a string like this one:
>
> TEST="apath/ anotherpath/*.txt"
> for d in $TEST
> do
>     echo "$d"
> done
>
> here i wanted to output:
>
>>apath
>>anotherpath/*.txt
>
> btw i just can not avoid shell to expand '*.txt' to 'file1.txt',
> 'file2.txt'; etc.
>
> i think i am missing something around 'TEST' in 'for d in $TEST' but i
> have no clues...

   Use "set -f" to disable filename expansion, then turn it back on
   afterwards with "set +f":

set -f
TEST="apath/ anotherpath/*.txt"
for d in $TEST
do
     echo "$d"
done
set +f

-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
0
Chris
5/8/2004 6:07:47 PM
Reply: