linux bash -l,linux-当bash称为sh时,为什么bash的行为有所不...

我有一台ubuntu机器,其默认shell设置为bash,并且两种方式都设置为$PATH中的二进制文件:

$which bash

/bin/bash

$which sh

/bin/sh

$ll /bin/sh

lrwxrwxrwx 1 root root 4 Mar 6 2013 /bin/sh -> bash*

但是,当我尝试调用使用the inline file descriptor的脚本(只有bash可以处理,但sh不能处理)时,两个调用的行为不同:

$. ./inline-pipe

reached

$bash ./inline-pipe

reached

$sh ./inline-pipe

./inline-pipe: line 6: syntax error near unexpected token `

./inline-pipe: line 6: `done <

我指的示例脚本看起来像这样

#!/bin/sh

while read line; do

if [[ "$line" == "reached" ]]; then echo "reached"; fi

done <

真正的更长一点:

#!/bin/sh

declare -A elements

while read line

do

for ele in $(echo $line | grep -o "[a-z]*:[^ ]*")

do

id=$(echo $ele | cut -d ":" -f 1)

elements["$id"]=$(echo $ele | cut -d ":" -f 2)

done

done <

echo ${elements[*]}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值