我在第 8 行收到错误:意外的令牌
#!/bash/bin/bash
echo -e "enter the filename: \c"
read file_content
if [ -f $file_content ]
then
if [ -w $file_content ]
then
echo "Please Press Ctrl+d to exit"
echo cat >> $file_content
else "You dont have permission to write"
fi
else
echo " You have file name $file_content"
fi
答案1
你的脚本看起来应该像这样:
#!/bin/bash
echo -e "enter the filename: \c"
something_to_add=/path/to/something_to_add/file
read -r file_content
if [ -f "$file_content" ]
then
if [ -w "$file_content" ]
then
echo "Please Press Ctrl+c to exit"
cat "$something_to_add" >> "$file_content"
else
echo "You dont have permission to write"
fi
else
echo "You have file name $file_content"
fi
错误提示:
情况如下:错误 (
#!/bash/bin/bash
) 正确 (#!/bin/bash
),更好 (#!/usr/bin/env bash
)。内部
if
语句有错误else
段。- 在必要时添加双引号。
- 而不是
echo cat >>
做cat >>
使用此在线服务检查您的脚本: