[Edit] I’ve summarized the answer to the following below, the error lies in the line:
[Edit] if [$1 ne $value]; then
I’m trying to pass a value to a command:
#!/bin/bash
for value in $(mycommand $1)
do
echo Found $value
if [$1 ne $value]; then
echo No match!
if
done
But if I type in the following to execute the script:
#./myscript 25
I get the error:
Found somestuff
./myscript: 25: command not found
What I’d like to do is pass in the first argument of the script (“25” in the example above) and send it to the command ‘mycommand’.
How can I do this?
Is that the complete
myscript? I tried your script as written and got no such error:If I add a
$1to the end of the script:Update to your edit: When using the
[command, you need to add some extra space, and also use-ne:The
[command is often implemented as a soft or hard link to thetestcommand, for example:The manual page for
testwill give more information about the valid expressions.