Solved

tcsh shell script expanding * as files

Posted on 2002-07-10
3
431 Views
Last Modified: 2008-03-04
Hello,

Here is a simple shell script saved in a file called "test":
_____________________________
if [ $# -gt 0 ]
then
        echo "arguments number $#"
        while [ $1 ]
        do
                echo "param $1"
                shift
        done
fi
_____________________________


If I launch it with "test *" and if in the directory there are two files "file1" and "test" here is the result:

__________
arguments number 2
param file1
param test
___________


My question is: why?
What I expected was:

___________
arguments number 1
param *
___________


Another thing strange (in my opinion), is that if I remove the "if" test lines like that:
___________________
echo "arguments number $#"
while [ $1 ]
do
        echo "param $1"
        shift
done
___________________

The result of the execution of the script "test *" is:

___________________
arguments number 2
while: Expression Syntax.
___________________


Do you have an idea?

Thanx
0
Comment
Question by:bonduel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
jlevie earned 200 total points
ID: 7143510
It is the shell that expands wildcards, not the script por program. So when you feed you script a command line containg a wildcard (*), the shell looks in the current (or specified path) for all files/dirs that match the wildcard and then invokes the script with those arguments.
0
 

Author Comment

by:bonduel
ID: 7143569
Yes you're right, thank you for you comment.
In fact, it is simple to avoid this by quoting the * like:
test "*"

I found this by doing some tests.

I think it is 200 wasted points, and some of your time.

Thank you again.
0
 

Author Comment

by:bonduel
ID: 7143590
Ha, and about the while error, I should replace the test:

    while [ $1 ]

with

    while [ "$1" != "" ]

Like this it works.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question