【shell 】bash file returns unexpected token `$‘do\r‘‘

bash file returns unexpected token `$'do\r'' - Stack Overflow

问题描述:

问题shell

#!/usr/bin/env bash

echo "The ports used are as follows:"

ports=( 8030 9020 9030 9010 9060 8040 9050 8060 8000 )
for num in ${ports[@]}
do
  netstat -tunlp |grep $num
done

运行报错:

[gaoliang@di11v ~]$ bash sc_check.sh
sc_check.sh: line 2: $'\r': command not found
The ports used are as follows:
sc_check.sh: line 4: $'\r': command not found
sc_check.sh: line 7: syntax error near unexpected token `$'do\r''
'c_check.sh: line 7: `do

问题解决

问题根本原因描述

This commonly is caused when the executable file is created in an operative system (windows) and used in another operative system (Linux). Also rare text editors could be the problem.

问题解决

using unix text editor vi:

open file in vi edit with vi filename.sh command;

type in vi :set ff=unix command;

save file with :wq

It will save the file with unix line endings.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

roman_日积跬步-终至千里

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值