我有一个在我的(美国)mac(osx 10.8.4)上编写的脚本,效果很好。然后我通过电子邮件将它发送给另一个(欧洲)mac(osx 10.8._)的人,它抱怨说:
syntax error near unexpected token `$'{\r''
case
在几个空行和语句的末尾。无处。
我找到了这个解决方案,最终解决问题的方法是使用名为dos2unix
.
我的问题是:这些DOS
转义字符是从哪里来的?!
过程:我通过 Terminal.app 在 emacs 中创建了程序。我将它附加到 Mail.app 中的电子邮件并发送。还尝试在 textedit 中打开它,选择所有文本,复制并粘贴到 Mail.app 电子邮件中。在 Gmail 中(使用通过 chrome 浏览器)做了同样的事情(附件和复制和粘贴),同样的问题。
有问题的脚本(***
在有错误的行中添加):
#!/bin/sh
***
DIR="mhd_3/"
APP="/Users/lzkelley/Applications/athena/athena4.1/vis/vtk/join_vtk"
FNAME="lzk_flux-cap-1"
LOG_FLAG=False
***
# --- Check for Command Line Arguments ---
***
while getopts hp:s:i:f:l: opt; do
case "$opt" in ***
#p) NUM_PROCS=$OPTARG;;
#s) NUM_SNAPS=$OPTARG;;
i) DIR=$OPTARG;;
f) FNAME=$OPTARG;;
l) LOG_FLAG=True; LOG=$OPTARG;;
h) usage;;
\?) printf "Invalid Option!\n"; usage;;
esac
done
***
printf "\nprocess_vtk.sh\n\n"
***
# Make sure directory ends with slash
DIR=$(echo "$DIR"|sed 's/\/$//g') # Remove slash if it has it
DIR=$DIR/ # Add slash
NUM_PROCS=$(find $DIR -type dir -name "id*" | wc -l) # Use word count to find num directories matching (id*) in output folder
NUM_SNAPS=$(find $DIR'/id0/' -name "$FNAME*.vtk" | wc -l) # Use word count to find num vtk files in target directory
# Adjust numbers for loops (i.e. 0 to [NUM-1] )
let "NUM_PROCS -= 1"
let "NUM_SNAPS -= 1"
# Iterate through each snapshot
for NS in `seq 0 $NUM_SNAPS`; do
printf -v jj ".%04i." $NS # Assume 4 digit numbering
OUTNAME=$DIR$FNAME".all"$jj"vtk" # Construct output filename from directory, file name base, and number
INNAMES="" # Names of input vtk files (for each processor)
# Iterate through each processor
for NP in `seq 0 $NUM_PROCS`; do
# Names are slightely different for 0th processor
if [ $NP = 0 ]; then
THIS=$DIR"id"$NP"/"$FNAME$jj"vtk" # Name of single vtk file
if [ -e "$THIS" ]; then
INNAMES=$INNAMES$THIS # Append to list
fi
else
THIS=$DIR"id"$NP"/"$FNAME"-id"$NP$jj"vtk" # Name of single vtk file
if [ -e "$THIS" ]; then
INNAMES=$INNAMES" "$THIS # Append to list
fi
fi
done # NP
echo $APP -o $OUTNAME $INNAMES
# Call the program to merge vtk files
$APP -o $OUTNAME $INNAMES
done # NS