我正试图通过bash脚本来自动化我的日常工作。为此,我需要创建以下逻辑脚本
从根用户切换到另一个linux用户打开指定路径
这是我的代码logic.sh
#! /bin/bash
su another_user
cd /home/another_user #tried with sudo too
logic.sh执行后
. logic.sh
我看到root用户切换到了/root,但我仍然停留在/root目录中。
我做错了什么或者bash脚本不适合于用户切换逻辑中的自动化逻辑
我有一个名为example.sh的脚本。
echo Write a number, please:
read x
let res=$x+1
echo $res
如果我以这种方式运行它,就会得到一个错误:
mario@gazpatxo-linux:~/temp$ sudo ./example.sh
[sudo] contraseña para mario:
Write a number, please:
3
./example.sh: 3: ./example.sh: let: not found
如果我以另一种方式运行它,就不会有错误:
mario@gazpatxo-linux:~/tem
我有一个名为test.sh的bash脚本,为了简单起见,它将一行打印到stdout,一行输出到stderr。
test.sh:
#!/bin/bash
echo "this is to stdout"
echo "this is to stderr" 1>&2
我想在下午7:00运行脚本test.sh,但前提是满足某些条件。为此,我有另一个名为schedule.sh的bash脚本,它检查一些内容,然后将命令提交给at,以便稍后运行。
我希望test.sh ( stdout和stderr)的输出在电子邮件中发送给我。我使用mailx来做这件事,这样我
我在试着安装网络。6.3在我的chromebook上使用Linux,但当我试图执行
./dotnet-install.sh -c Current
在Linux终端中,总是会出现以下错误:
-bash: ./dotnet-install.sh: No such file or directory
有什么办法可以绕过它/解决它吗?
我已经完成了sudo -i,所以我获得了完全的许可,并且我已经将我要执行的文件放在很多文件夹中,包括我的Linux文件夹。
任何帮助都是非常感谢的!
我有var.sh
name="John"
age="29"
我还有main.sh
eval "var.sh"
echo "My name is $name"
当我跑的时候,我一直在
⚡️ Desktop bash main.sh
main.sh: line 1: var.sh: command not found
My name is
将本地bash文件导入另一个bash文件的最佳实践是什么?
有办法在Mac、Linux和Windows上工作吗?
我已经将以下代码保存为.sh文件,并从我的根目录执行它:
有几个错误:
script.sh: line 65: conditional binary operator expected
script.sh: line 65: syntax error near `=~'
script.sh: line 65: `while [[ $1 =~ ^\- ]]; do'
然后,当我运行git-rewrite-history命令时,我收到一个错误:
'git-rewrite-history' is not recognized as an internal or ext
我想使用make构建我的程序,然后通过bash脚本启动创建的可执行文件,但是bash找不到可执行文件,尽管它是创建的,我可以手动启动它。该问题仅存在于Gnome-terminal中的linux mint 19上。Edit:确切的错误消息是:"/path/to/my/executable:没有这样的文件或目录“ 我有一个跨平台的项目,我需要运行cmake,然后构建项目,最后启动创建的可执行文件。我有一个bash脚本来自动化这个过程: Edit:它是唯一引起问题的部分;) for TASK in $@; do
if [[ $TASK == "make" ]]; t
我在linux机器上有一个用java写的rest服务。
我使用的是:
p = Runtime.getRuntime().exec(cmmnd);
或
ProcessBuilder pb = new ProcessBuilder(cmmnd).inheritIO();
p = pb.start();
p.waitFor();
我可以执行像mkdir,touch这样的命令...但是当我尝试运行sh文件时,什么也没有发生(例如:sudo sh /home/mydir/myfile.sh)
这是权限问题吗?我该如何解决这个问题呢?
我试图双击一个这样做的文件:
#!/bin/bash
#Mount USB Jump, Copy files to it, Unmount it.
[open terminal (so that I can see what 's going on)]
pmount /dev/sdc JUMP
sleep 2s
cp -p -u source/path/ destination/path/
read -p "Press enter to unmount Jump or ctrl c to abort."
pumount /dev/sdc
[close terminal
这里我有一个脚本,它导出一些必要的路径在Linux中。运行此脚本后,我必须运行一些其他脚本。
我有两个脚本
1 import.sh = importing paths
2 main.sh = this script do something with HCI (use for Bluetooth purpose).
当我运行./import.sh,然后运行./main.sh时,它就会给出错误。当我运行. ./import.sh,然后运行./main.sh时,它工作得很好。
那么./import.sh和. ./import.sh之间的区别是什么呢
如果我以超级用户身份运行脚本,会发生什么
我想使用test.sh来执行hello.py。但是,test.sh似乎将hello.py读取为sh文件。 错误消息 line 1: syntax error near unexpected token `'hello'' test.sh #!/user/bin/ python (which python path)
ARRAY=(1 2 3 4)
for num in ${ARRAY[@]}; do
/artic/m-yasunaga/work/korin-3/src/example/hi.py
echo $num"th loop"
d