这里我有一个脚本,它导出一些必要的路径在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之间的区别是什么呢
如果我以超级用户身份运行脚本,会发生什么
将/tmp/template.txt文件复制到$1中指定的任何目录的示例脚本。
copy_script.sh
if [ $# -eq 0 ]; then
echo No Argument
echo "Usage: $0 "
else
cp /tmp/template.txt $1
fi
在此之前
wolf@linux:~$ ls -lh
total 4.0K
drwxrwxr-x 2 wolf wolf 4.0K Dis 31 10:08 'another directory'
wolf@linux:~$
测试脚本
wolf@linu
我有一个用java编写的程序,它使用第0个参数作为文件位置,如下所示
File f = new File(args[0]);
因此,当我使用windows批处理(.bat)文件执行它时,它可以正常工作。但是,当我在linux中使用linux shell文件(.sh)执行相同的命令时,我得到的是ArrayIndexOutOfBoundsException。
WINDOWS批处理文件:
@echo off
for /f %%i in ("%0") do set scriptpath=%%~dpi
set cp=%scriptpath%/../lib/*.jar;
java -cla
我是Linux的初学者,我一直在学习shell脚本,而且我很难理解位置参数。我第一次在终端输入的内容如下:
set this is a great place
我跑了:
echo $1
它显示:
this
然后我在shell脚本文件test.sh中尝试了一些东西。
#!/bash/sh
echo $1
我在终端上运行shell脚本:
sh test.sh
什么都没显示出来。如果我跑了
sh test.sh hello
它将在屏幕上显示hello。但是,如果我只是跑:
echo $1
在终端命令行上。它仍然会显示给这个
为何两地1元的价值是不同的呢?
当命令被指定为CMD a b c时,一切都按预期的方式工作,同时使用CMD ["a", "b", "c"]指定相同的命令--它会产生意想不到的结果。我想在码头里运行朱庇特(ipython)。我的CMD命令是启动它。似乎不管我怎么说--木星开始了。但是,只有当我将它指定为CMD a b c时,jupyter才能正常工作,并且可以启动内核。在本例中,“Notebook”命令工作
FROM debian:stable
RUN apt-get update && apt-get install -y wget bzip2
我有一个关于Linux上shell脚本的问题。我试着做这个:
$ sh << EOF
#!/bin/sh
function test {
echo test
echo test2
}
test
EOF
结果是:
test
test2
但是,如果我想运行带有参数的脚本,而不将它保存到文件中呢?
$ sh $1 test1 test2 << EOF
#!/bin/sh
function test {
echo $2
echo $3
}
test
EOF
我该怎么做?
我在crontab中有下面一行。
@reboot /usr/bin/teamspeak3-server_linux-amd64/ts3server_minimal_runscript.sh
当我重新启动时,脚本在后台运行(即我的terminal 3服务器启动),但我试图找到如何阻止它(我不能只是ctrl+c终端,因为它现在正在后台运行)。一个论坛帖子说通过使用下面的命令来终止这个过程。
ps -ef | grep -i XXXX: to find your background running process
kill OID : kill your unnecessary process
我有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上工作吗?
这是剧本
user@linux:~$ cat script.sh
#!/bin/bash
for i in `seq $#`
do
echo $i
done
user@linux:~$
输出
user@linux:~$ ./script.sh a b c
1
2
3
user@linux:~$
Desired输出
我想得到这样的论证价值.而不仅仅是数字
user@linux:~$ ./script.sh a b c
1 - a
2 - b
3 - c
user@linux:~$
我最近刚开始对scala进行编程,在“scala中的编程”(www.artima.com/pins1ed)一书中,介绍了在linux中执行scala脚本的以下方法:
#!/bin/sh
exec scala "$0" "$@"
!#
// Say hello to the first argument
println("Hello, "+ args(0) +"!")
现在我已经使用linux很长时间了,但是bash脚本不是我的专长。现在我可以猜到这种scrpt是如何工作的(而且它运行得很好),但是我想知道!#和$@到底做了什么。
我在Linux和solaris下运行相同的脚本。下面是脚本:
#!/bin/sh
index=0
ls /tmp | grep e |
while read fileWithE
do
echo $fileWithE
index=`expr $index + 1`
done
echo "index is $index"
由于while循环在子while中运行,所以在solaris和linux中,我期望'index is 0‘作为输出。但是在solaris中,$index是/tmp下包含'e‘的文件的实际数量。那么,虽然循环不会在solaris下的
在这两个for语句中,我都得到了以下错误:
./count_files.sh: line 21: [: too many arguments
./count_files.sh: line 16: [: too many arguments.
有人能帮我吗?
#!/bin/bash
files=($(find /usr/src/linux-headers-3.13.0-34/include/ -type f -name '[aeiou][a-z0-9]*.h'))
count=0
headerfiles=($(find /usr/src/linux-headers-3.