我有两种执行bash脚本的tcl脚本:
#exec bash ./run.sh
open "|bash ./run.sh r"
bash脚本如下所示:
#!/bin/bash
ls
if [ "$?" != "0" ]; then
echo "ERROR: Status failed!" > status
else
echo "Everything is OK!" > status
fi
我使用tclsh for Windows和git bash中的bash。当我使用:
exec bas
在Mac (山狮)下,我有一个shell脚本"a":
#!/bin/bash
open -a Terminal b
它使用终端运行另一个shell脚本"b“:
echo `pwd`
有趣的是,无论我正在运行的脚本位于何处,"b“中的pwd命令总是返回主目录。
问题:
这一切为什么要发生?
如何将运行环境设置为工作目录而不是主目录(即到达pwd时返回工作目录)
使用bash,我试图用空格替换目录名称中的所有点,以及它的子目录。
示例:目录di.1.3将变成dir 1 3
到目前为止,我的剧本是:
#!/bin/bash
for dir in *\ -\ *; do
[[ -d "$dir" ]] || continue # skip if not a directory
sub="${dir#* - }"
if [[ ! -e "$sub" ]]; then
mv "$dir" "$sub"
正如所描述的,[set]中的Bash可以匹配set中的任何字符,
在下面的目录中,我在当前目录中有名为a,b,c的3个dirs:
$ ls
a b c
$ ls [abd] # just as expected,show dirs a and b
a:
b:
$ ls [bd] # expecting show dir b but noting matched
$ ls [ad] # expecting show dir a but noting matched
can someone explain this to me?thanks!
我编写了一个bash脚本,它创建了一系列目录,并将项目克隆到选定的目录中。
为此,我需要对每个目录(project 1和project 2)进行cd,但是脚本既不对第二个目录进行D3,也不执行命令。
相反,它在cd之后停止,并在project2目录中克隆。为什么它不在下面的代码中调用cd_project1函数?
#!/bin/bash
#Get the current user name
function my_user_name() {
current_user=$USER
echo " Current user is $current_user"
}
我有一个简单的bash脚本simple.sh,如下所示:
#/usr/local/bin/bash
for i in $1
do
echo The current file is $i
done
当我使用以下参数运行它时:
./simple.sh /home/test/*
它将只打印并列出位于目录中的第一个文件。
但是,如果我将simple.sh更改为:
#/usr/local/bin/bash
DIR=/home/test/*
for i in $DIR
do
echo The current file is $i
done
它将正确地打印
在使用Bash的Ubuntu16.04中,当我无法方便地升级所有WordPress组件(核心、翻译、主题、插件)时,我遇到了一个问题,我使用了以下代码来解决这个问题:
cat <<-EOF > /etc/cron.daily/cron_daily
#!/bin/bash
drt="/var/www/html"
for dir in "$drt/*/"; do
if pushd "$dir"; then
wp plugin update --all --allow-r
专家们
我想在每个文件夹中创建文件。这是我的命令
for i in `ls`;do cd $i;touch test.txt;done
-bash: cd: 10/: No such file or directory
-bash: cd: 2/: No such file or directory
-bash: cd: 3/: No such file or directory
-bash: cd: 4/: No such file or directory
-bash: cd: 5/: No such file or directory
-bash: cd: 6/: No such fi