当符号链接使用sh和bash的区别 [英] difference between sh and bash when symlink is used

查看:179
本文介绍了当符号链接使用sh和bash的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用进程替换

该脚本是:

  #!/bin/bash
  while read line
  do
    echo "$line"
  done < <( grep "^abcd$" file.txt )

当我使用运行脚本SH file.sh 我得到以下输出

When I run the script using sh file.sh I get the following output

$sh file.sh
file.sh: line 5: syntax error near unexpected token `<'
file.sh: line 5: `done < <( grep "^abcd$" file.txt )'

当我运行使用庆典file.sh 脚本,该脚本的工作原理。

When I run the script using bash file.sh, the script works.

有趣的是, SH 软链接映射到 /斌/ bash的

$ which bash
/bin/bash
$ which sh
/usr/bin/sh
$ ls -l /usr/bin/sh
lrwxrwxrwx 1 root root 9 Jul 23  2012 /usr/bin/sh -> /bin/bash
$ ls -l /bin/bash
-rwxr-xr-x 1 root root 648016 Jul 12  2012 /bin/bash

我测试,以确保符号链接正在使用以下遵循我的外壳:

I tested to make sure symbolic links are being followed in my shell using the following:

$ ./a.out
hello world
$ ln -s a.out a.link
$ ./a.link
hello world
$ ls -l a.out
-rwx--x--x 1 xxxx xxxx 16614 Dec 27 19:53 a.out
$ ls -l a.link
lrwxrwxrwx 1 xxxx xxxx 5 May 14 14:12 a.link -> a.out

我无法理解为什么 SH file.sh 不执行为 /斌/ bash的file.sh 因为 SH 是一个符号链接 /斌/庆典

I am unable to understand why sh file.sh does not execute as /bin/bash file.sh since sh is a symbolic link to /bin/bash.

任何见解将大大AP preciated。谢谢你。

Any insights will be much appreciated. Thanks.

推荐答案

在sh的时候,bash的进入POSIX
       启动文件后模式下读取。替代的过程中没有POSIX模式的认可。据POSIX,≤(富)应当从命名的文件直接输入(富)。 (嗯,这是,根据我的标准读数。语法是模糊的,在许多地方。)

When invoked as sh, bash enters posix mode after the startup files are read. Process substitution is not recognized in posix mode. According to posix, <(foo) should direct input from the file named (foo). (Well, that is, according to my reading of the standard. The grammar is ambiguous in many places.)

Edit:从 bash的手动

The following list is what’s changed when ‘POSIX mode’ is in effect:
...
Process substitution is not available.

这篇关于当符号链接使用sh和bash的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆