bash: syntax error near unexpected token `<'
i have this 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"
but when i run this code in terminal
./build.sh <Project ov7670_VDMA_VGA><v3>
i get this error
bash: syntax error near unexpected token `<'
Solution 1:
As two people commented, the syntax for calling the script uses characters that are not meant to be taken literally. The angle brackets in:
<Project Name> <Version>
imply that the Project Name and Version are required parameters. This is confirmed in the shell script code where it explicitly checks for two parameters:
if [ $# != 2 ]
then
echo "Invalid arguments."
...
The correct way to call the script would be:
./build.sh "Project ov7670_VDMA_VGA" v3
... where I've quoted the first parameter so that the space between "Project" and "ov7670_VDMA_VGA" does not get misinterpreted as two separate arguments.