./ . 和#!/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
总结:
Linux 解释脚本按使用 shell 的顺序是
1) 脚本第一行中 #!指定
2) 没有指定就使用 $SHELL
而使用 . 就是在当前 shell 中执行,当然就不会关注 !#/bin/sh 中的指定了.