我有这个 bash
#!/bin/bash
set -o nounset
if [ $# != 2 ]
then
echo "Invalid arguments."
echo "Try: $0 <Project Name> <Version>"
exit
fi
if [ -d ./$1 ]; then
echo "Error: Project $1 exists."
exit
fi
vivado -mode batch -source create_vivado_proj.tcl -tclargs $1 $2
xsdk -batch -source create_sdk_proj.tcl $1 $2
curr_dir=`pwd`
project_dir="$curr_dir/$1"
# Create bootable files
mkdir "$project_dir/boot"
fsbl_path="$project_dir/$1.sdk/fsbl/Debug/fsbl.elf"
bit_path="$project_dir/$1.runs/impl_1/system_wrapper.bit"
config_path="$project_dir/$1.sdk/sysconfig/Debug/sysconfig.elf"
bif_path="$project_dir/boot/boot.bif"
echo "the_ROM_image:" > $bif_path
echo "{" >> $bif_path
echo " [bootloader]$fsbl_path" >> $bif_path
echo " $bit_path" >> $bif_path
echo " $config_path" >> $bif_path
echo "}" >> $bif_path
# Create BOOT.bin
bootgen -image "$bif_path" -o i "$project_dir/boot/BOOT.bin"
echo "Generate BOOT.bin at"
echo "$project_dir/boot/BOOT.bin"
但是当我在终端运行此代码时
./build.sh <Project ov7670_VDMA_VGA><v3>
我收到这个错误
bash: syntax error near unexpected token `<'
答案1
正如两个人所评论的那样,调用脚本的语法使用了不按字面意思理解的字符。以下是尖括号:
<Project Name> <Version>
暗示项目名称和版本是必需参数。这在 shell 脚本代码中得到了证实,它明确检查了两个参数:
if [ $# != 2 ]
then
echo "Invalid arguments."
...
调用脚本的正确方法是:
./build.sh "Project ov7670_VDMA_VGA" v3
...我引用了第一个参数,以便“Project”和“ov7670_VDMA_VGA”之间的空格不会误解作为两个独立的论点。