我用linux bash编写了一个简单的脚本,就像下面这样:
#!/bin/bash
PATH=/tmp_with_zip_files
FILETYPE=zip
i=1
for filename in $PATH/*.$FILETYPE;
do
echo "rm $filename";
if [ -f $filename ];
then rm $filename;
fi
i=$((i+1))
done
echo "$i files removed"
但是,当
我正在尝试运行一些bash脚本,这些脚本是我们在上在Linux上编写的。脚本执行一个
#!/bin/bash
sudo su -l <username> << EOF
echo $HOME
#execute command that is only on the path of <username>
EOF
不,我以user1的身份运行脚本,在脚本中我试图切换到user2。实际上,我需要它像这样运行,因为还有其他部分需要以user1的形式运行。
在linux上我得到
/home/user2
在上我得到
/Users/user1
因此,它实际上并不执行登录,
如果我是在Linux终端中,并且开始设置变量,比如导出AGE=45。
然后我有一个脚本来读取终端变量中的用户数据并对其进行处理,这有可能吗?
IE:
user@linux$ export AGE=45
user@linux$ ./age.sh
#script asks for input
read -p "what is your age?" scriptAGE
#user inputs variable set in terminal
$AGE
#回波输出
echo "your age is: " $scriptAGE"
#应该说你的年龄
我已经写了一个脚本,它将在AmazonLinux2.0上默默地安装Microstrategy
在我的主脚本中,我调用Microstrategy安装脚本,它在/bin/ksh中,我的在/bin/bash中。
mstr_install.sh如下:
#!/bin/bash
#DATE 22-FEB-2019
#DISCRIPTION: IT will Install MSTR-11.1 with Silent Options using optins.txt file
DATE=$(date +"%Y-%m-%d_%T")
PATH="/app/soft/Installati
我试图使用一个环境变量指向一个文件,通过一个子程序运行它并将它与一个变量相关联。我用Windows实现了它,但我无法使语法在Linux上工作。
这就是我所拥有的:
my $config = read_config("$ENV{APP_HOME}/config/APP-linux.cfg");
当我的脚本到达这一行时,我的脚本会死掉:
Use of uninitialized value $ENV{"APP_HOME"} in concatenation (.) or string at ./XXXXX.pl
APP_HOME被定义为环境变量(使用set
有没有可能将一个脚本中设置的环境变量传递给竹子中的另一个?
例如,我按如下方式设置Go,并希望后续任务(脚本)能够访问我在此处导出的路径和GOPATH。
set -e
if [ ! -d "go" ]; then
wget -q https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz
tar -xzf go1.5.linux-amd64.tar.gz
fi
export GOROOT=$(pwd)/go
mkdir -p gopath/
export GOPATH=$(pwd)/gopa
我对Linux中的脚本编写很陌生,我认为我对在命令替换中使用变量感到困惑,越多地了解和阅读它。有人能给我解释一下下面的情景吗?
在我的ksh脚本中,我试图在sqlplus脚本中使用ksh变量,如下所示:
temp_var="'a', 'b'"
randomVar=$(sqlplus -s $con_details <<EOF
update table ABC
Set field1='val'
Where field2 NOT IN ("${temp_var}");
EOF)
但是,上面的语法会导
我已经编写了shell脚本,它从输入文件中读取命令并执行命令。我有这样的命令:
cat linux_unit_test_commands | grep "dmesg"
在输入文件中。在执行shell脚本时,我收到下面的错误消息:
cat: |: No such file or directory
cat: grep: No such file or directory
cat: "dmesg": No such file or directory
剧本:
#!/bin/bash
while read line
do
output=`$line
我有这个脚本,它处理包含windows文件路径的行。但是,该脚本在Linux上运行。有没有办法改变os库,让它在linux上运行时进行Windows文件路径处理?
我是这样想的:
import os
os.pathsep = '\\'
(由于某些原因,os.pathsep无法工作;因此无法工作)
我的脚本:
for line in INPUT.splitlines():
package_path,step_name = line.strip().split('>')
file_name = os.path.basename(package_
我想用shell脚本打印一个文件夹的结构。所以它看起来就像这样
File : linux -3.14/COPYING
File : linux -3.14/CREDITS
Directory : linux -3.14/Documentation
File : linux -3.14/Documentation/00 - INDEX
Directory : linux -3.14/Documentation/ABI
File : linux -3.14/Documentation/ABI/README
这是我的脚本。问题是它会打印出当前目录的所有
最近,我用这种regex测试编写了一个脚本:
# Works fine on Sabayon/Mac, doesn't work on CentOS
[[ $line =~ (.+)\{(.+)\} ]] || continue
它在Sabayon Linux和Mac上运行很顺利,但是我需要在其他环境下运行它,而脚本失败了。它是CentOS Linux。过了一段时间,我发现我需要避免出现双重反弹,才能让它发挥作用。
# Works fine on CentOS, does not on Sabayon/Mac
[[ $line =~ (.+)\\{(.+)\\} ]] || conti
我有一个简单的脚本如下。
names=("windows" "ubuntu" "raspbian" "debian" "kali linux")
echo "names array length: ${#names[@]}"
for n in ${names[@]}; do
echo $n
done
我的意图和希望是:
names array length: 5
windows
ubuntu
raspbian
debian
kali linux
但结果却是:
names array len