首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

./ . 和#/bin/bash 辨析Linux怎么选择当前执行脚本的shell

2013-09-12 
./ . 和#!/bin/bash 辨析Linux如何选择当前执行脚本的shell最近遇到一个有趣的问题,让我搞清楚Linux如何选

./ . 和#!/bin/bash 辨析Linux如何选择当前执行脚本的shell

最近遇到一个有趣的问题,让我搞清楚Linux如何选择当前执行脚本的shell


执行cts的的 media stress test 需要安装 android-cts-media-1.0.zip

把这个文件解开,发现有一个 copy_media.sh 脚本,就是用 adb push 向 android devices 复制文件,很简单的一个脚本,执行起来却有错

$./copy_media.sh 1920x1080

head copy_media.sh #!/bin/sh# Copyright (C) 2012 The Android Open Source Project## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at##      http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software

而用 . (就是 source 命令) 绕开了 #!/bin/sh;另一种方法是删除这行,就会使用$SHELL变量执行的shell;当然改成#!/bin/bash 也可以解决问题。


总结:

Linux 解释脚本按使用 shell 的顺序是

1)  脚本第一行中 #!指定

2) 没有指定就使用 $SHELL 

而使用 . 就是在当前 shell 中执行,当然就不会关注 !#/bin/sh 中的指定了.


热点排行