问题
I have the following shell script (named test):
#!/bin/sh
echo "junk"
filename="junk"
echo $filename
filename=`ls -t|head -n1`
echo $filename
when I run this script there is no output to the terminal. I am using red hat / putty.
What am I missing?
回答1:
You're accidentally running the system command called test, which produces no output. You need to use ./test instead to find the script in the current directory, whereas test will use the built-in shell command (and even if it didn't, it would find /usr/bin/test instead).
This is why you should avoid calling your test programs test. Try try instead.
来源:https://stackoverflow.com/questions/38667256/no-output-from-unix-shell-script