关于bash和sh

sh/bash/dash/ksh/zsh等Shell脚本
头像
tosail2010
帖子: 83
注册时间: 2011-03-27 19:01
联系:

关于bash和sh

#1

帖子 tosail2010 » 2011-04-26 16:22

我用的是Ubuntu10.04
输入命令:echo $SHELL
显示:/bin/bash

如果我执行shell脚本,脚本中无#!/bin/sh。
脚本是在bash,还是在sh中运行呢。
A year's plan starts with spring.
头像
lilydjwg
论坛版主
帖子: 4249
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 关于bash和sh

#2

帖子 lilydjwg » 2011-04-26 16:28

tosail2010 写了:我用的是Ubuntu10.04
输入命令:echo $SHELL
显示:/bin/bash

如果我执行shell脚本,脚本中无#!/bin/sh。
脚本是在bash,还是在sh中运行呢。
你加上呗
头像
灰色小狼
帖子: 4585
注册时间: 2008-12-06 10:38
系统: Arch

Re: 关于bash和sh

#3

帖子 灰色小狼 » 2011-04-26 16:38

没有就默认
头像
ebok
帖子: 852
注册时间: 2008-02-15 0:09

Re: 关于bash和sh

#4

帖子 ebok » 2011-04-26 16:58

没有的话就是一组命令的组合,shell内建的条件测试,循环等全部不能用.
Somebody think they are full of niubility, so they play a zhuangbility, but only reflect their shability.
头像
lexdene
帖子: 434
注册时间: 2010-02-21 16:19
来自: 大连
联系:

Re: 关于bash和sh

#5

帖子 lexdene » 2011-04-26 20:33

我印象中没有sh这个程序,只有bash这个程序。
而/bin/sh实际上只是一个指向/bin/bash的链接。
您可以看一下,我记不清了。

代码: 全选

ls -l /bin/sh
看看它是不是一个链接。
头像
lilydjwg
论坛版主
帖子: 4249
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 关于bash和sh

#6

帖子 lilydjwg » 2011-04-26 21:27

lexdene 写了:我印象中没有sh这个程序,只有bash这个程序。
而/bin/sh实际上只是一个指向/bin/bash的链接。
您可以看一下,我记不清了。

代码: 全选

ls -l /bin/sh
看看它是不是一个链接。
我表示您的印象非常不准确。Ubuntu 下,sh 是 dash 的软链接。
头像
tosail2010
帖子: 83
注册时间: 2011-03-27 19:01
联系:

Re: 关于bash和sh

#7

帖子 tosail2010 » 2011-04-27 8:21

灰色小狼 写了:没有就默认
我如何知道默认的是哪种?
A year's plan starts with spring.
levee
帖子: 3030
注册时间: 2009-10-03 23:31

Re: 关于bash和sh

#8

帖子 levee » 2011-04-27 9:45

bash兼容sh。
头像
link_01
帖子: 1024
注册时间: 2008-11-05 13:24

Re: 关于bash和sh

#9

帖子 link_01 » 2011-04-27 10:28

bash可以以sh的模式运行,它是根据名称来分辨的
用#!/bin/sh的话就是传统shell。
笔记
-------------------------------------
http://blog.163.com/wqt_1101
头像
fanhe
帖子: 2357
注册时间: 2007-03-24 23:45

Re: 关于bash和sh

#10

帖子 fanhe » 2011-04-28 9:25

sh现在的意义多数在于泛指了,在debian系当中,它是一个软链接,它根据情况可以是dash,bash等等,默认是dash
dash是很标准的shell语法,没有任何扩展功能,速度比bash快一些
我建议还是写兼容性最好的脚本吧,虽然很多系统都有bash

类似于,同是c语言,但是有gcc,clang编译器
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 关于bash和sh

#11

帖子 eexpress » 2011-04-28 9:33

fish csh zsh tcsh ksh dsh psh
● 鸣学
头像
lilydjwg
论坛版主
帖子: 4249
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 关于bash和sh

#12

帖子 lilydjwg » 2011-04-28 12:12

eexpress 写了:fish csh zsh tcsh ksh dsh psh
没有 ash?
头像
tosail2010
帖子: 83
注册时间: 2011-03-27 19:01
联系:

Re: 关于bash和sh

#13

帖子 tosail2010 » 2011-04-29 9:05

eexpress 写了:fish csh zsh tcsh ksh dsh psh
这是为什么?

谢谢各位的解答,我想多了解一些关于shell的资料。有没有好点的网站或者书。推荐一下。
附件
dd.JPG
dd.JPG (5.57 KiB) 查看 1290 次
A year's plan starts with spring.
头像
adam8157
帖子: 2794
注册时间: 2009-03-05 16:31
联系:

Re: 关于bash和sh

#14

帖子 adam8157 » 2011-04-29 9:15

link_01 写了:bash可以以sh的模式运行,它是根据名称来分辨的
用#!/bin/sh的话就是传统shell。
事实上, 即使传过去$0是sh, 也会比真正的sh多些功能, 导致未觉察的不兼容情况出现...
头像
fanhe
帖子: 2357
注册时间: 2007-03-24 23:45

Re: 关于bash和sh

#15

帖子 fanhe » 2011-04-29 9:16

tosail2010 写了:
eexpress 写了:fish csh zsh tcsh ksh dsh psh
这是为什么?

谢谢各位的解答,我想多了解一些关于shell的资料。有没有好点的网站或者书。推荐一下。
《高级Bash脚本编程指南》
google这本书
回复