我试图使用bash脚本显示某些细节,但是bash脚本的输出与终端的输出不同。
终端输出:
ubuntu@ubuntu:~/ubin$ cat schedule.text | grep 09/06/12
Sat 09/06/12 Russia 00:15 Czech Republic A
Sat 09/06/12 Netherlands 21:30 Denmark B
ubuntu@ubuntu:~/ubin$
Bash脚本输出:
ubuntu@ubuntu:~/ubin$ bash fixture.sh
Sat 09/06/12 Rus
我没有给出真实的例子,因为这篇文章太长了,以至于没有人会读它。所以我会给出其他例子,我有一个bash脚本name.sh,它被编程如下-
#!/bin/bash
echo "Please Enter your name"
read name
echo "Hello $name"
sudo bash age.sh
另一个脚本(比如age.sh)是这样的-
#!/bin/bash
*echo "Hello $name"
echo "Please enter your age"
read age
echo "Thank you
我们有父bash脚本
parent_source.bash
#!/bin/bash
source child_test.bash
在child_test.bash内部
echo $@
#Doing some validation checks for $@, for child_script command line arguments are optional
执行时的位置
source parent_source.bash one two
子脚本在$@中接受“1”和“2”,所以验证失败了,它没有将子脚本视为零参数。子脚本假设它有2个命令行参数。
但是,如果我们为子程序提供命令行arg
我正在尝试编写一个bash脚本,可以从它的执行中提取变量。
我真的不能很好地解释这一点,但是我想从相同的bash脚本中获得一个变量。
假设在这个例子中,我编写的脚本是CMD.sh。
sh ./CMD.sh foobar
var = foobar
如果这是可能的话,我怎么能在脚本中做到这一点呢?
sh ./CMD.sh foo bar fubar
var1 = foo
var2 = bar
var3 = fubar
如何创建一个脚本--一个bash.sh脚本,它可以从上面的变量中提取并使用它
脚本的名称是InstallmDNS.sh
脚本内容如下:
#!/bin/bash
sethostname() {
if [ $# -eq 1 ]
then
hostnamectl set-hostname "$1"
sed -i "/127.0.1.1/d" /etc/hosts
sed -i "/127.0.0.1/a\127.0.1.1 $1" /etc/hosts
reboot
else
echo "The exapmle of execute the script: b
大家下午好,
这可能是一个不需要思考的问题,但我目前遇到了一些问题,将一个变量传递给bash脚本中的程序。
我想做的是:
regions=ne,se,vt,ma,sw,nw and so on and so forth
在bash脚本中定义了这个变量之后,我想将这个变量传递到GrADS中,在这里,我的脚本将逐个读取每个区域,直到它到达末尾。
我只是在想,有没有什么办法可以先获取一个文件,然后再跟踪该文件的来源?
我在我的bash脚本上使用,我在主脚本上使用easyoption.sh,它工作得很好。但是,当我有其他脚本稍后从主脚本加载时,我希望获得帮助,并且-- easyoptions.sh应该在最后加载的文件上工作。
示例:
test.sh
#!/bin/bash
## EasyOptions Sub Test
## Copyright (C) Someone
## Licensed under XYZ
## -h, --help All client scripts have this, it
我有以下问题:
我尝试通过cygwin从windows调度程序启动perl脚本。
我执行的步骤是:使用perl脚本的参数调用process.bat中的bash文件
症状:如果我直接从cygwin调用"perl scriptpath“,如果我用bash从windows cmd调用脚本,它就不会工作。
命令: C:\cygwin\bin\bash.exe --login /cygdrive/c/scripts/testscript.pl它输出以下内容:
Line 3: use: command not found
Line 4: use: command not found
Can'