Reputation: 73
I'm trying to get a feel for Unix so that I can write a short program in UNIX csh that takes stdin and returns stdout. So I wrote the following code:
echo "TEST"
echo -n "Input: "
set TEST = "$<"
echo $TEST
However I keep getting an error that I can't quite figure out when I type in certain characters. For example,
Run 1: No question mark. As you can see, it runs exactly as I want it to.
edoras ~/As4[199]% ./scriptp1
TEST
Input: www.google.com/search
www.google.com/search
Run 2: With question mark. Suddenly, there's a "no match" error.
edoras ~/As4[201]% ./scriptp1
TEST
Input: https://www.google.com/search?criteria
echo: No match.
So what is this error and how do I go about fixing it? Because for the actual program I have to write I have to be able to read all special characters and print out their ASCII codes.
Upvotes: 3
Views: 19576
Reputation: 73
Alex is right in his answer. The "?" is one of a series of metacharacters reserved in UNIX for special commands, so in order to print them we would have to jump through some hoops that I haven't quite figured out yet. But at the very least now I know why I'm getting that output.
"?" is a matching command, so, like Alex said, it's trying to match my input to something that isn't there, instead of printing out as a plain old text character with no special value.
Upvotes: 0
Reputation: 4430
From the tcsh
manual page:
Unless enclosed in
'"'
or given the':q'
modifier the results of variable substitution may eventually be command and filename substituted.
Since the variable is not quoted, the shell attempts filename substitution, which fails because you probably don't have a file matching search?citeria
in a subdirectory named www.google.com
in a subdirectory named https:
in the current directory. "No match" means that filename substitution failed. From the same manual page:
It is an error for a glob-pattern containing
'*'
,'?'
,'['
or'~'
, with or without'^'
, not to match any files.
The technical answer ends here. The rest is purely opinion-based.
Please note that unless you have specific good reasons it is usually considered preferable to write scripts in a POSIX-compatible shell, simply because csh
-compatible shells are not always available by default. I think that as a beginner you should really first learn to write scripts in a POSIX-compatible shell and only afterwards, if needed, consider csh
-compatible shells.
Upvotes: 3