当我第二次运行bash脚本时,是否可以使用它使bash脚本从特定的行开始。
#!/bin/bash
#installed jq by using sudo apt-get install jq
# return indices and os,process
a=$(curl -XGET 'http://localhost:9200/_nodes/node01/stats/os,process?pretty=1')
#return just jvm
b=$(curl -XGET 'http://localhost:9200/_nodes/node01/stats
我正在创建一个Docker容器,它需要创建特定的bash脚本。我在Dockerfile中使用了以下运行语句:
RUN printf "#!/bin/bash\n \
# This is a bash comment inside the script\
ls -l" > /home/myuser/script.sh
它工作得很好,但是得到的脚本只是:
#!/bin/bash
ls -l
因此,bash注释在最终文件中丢失了。我怀疑原因是Docker假定该行是Dockerfile注释,但由于它包含在双引号中,我认为显然不是这样。
当然,我可以通过将完整的脚本包含在一行中,或
我尝试测试字符串是否以某个前缀开头。但我的脚本似乎不起作用(我希望"if“分支不会运行)。一些Bash专家可以帮你看一下吗?谢谢!
以下是我的代码和测试结果:
$ cat testb.bash
#!/bin/bash
my_var="abcdefg";
if [[ "${my_var:0:5}"=="order" ]]; then
echo "value of my_var is ${my_var}.";
fi;
if [[ "${my_var:0:5}" -eq "order"
我正在尝试创建一个bash脚本来替换所有
<?= /* @noEscape */ __('any random string, of any length') ?>
使用
<?= $block->escapeHtml(__('any random string, of any length')) ?>
在特定的文件或目录中。
问题是内部字符串可以是任何东西。
到目前为止,我已经尝试过使用sed。也许这不是最好的方法。
有什么想法吗?
#!/bin/bash
sed 's/\/\* @noEscape \*\/ __\(
我最近使用软件中心安装了apache2包,我想要创建一个别名apacheres,它将取代更麻烦的命令/etc/init.d/apache2 restart。
我在我的主目录中打开了.bashrc文件,它包含以下几行:
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the
当我从回购公司git clone,我得到,
fatal: Could not get current working directory: No such file or directory
我做什么好?我已经检查了服务器并发现存在.git文件。服务器正在运行一个Gitlab实例。我已经用键正确地配置了ssh,并且我已经提交&克隆了一段时间了,没有任何错误,这是突然发生的。
FWIW,我是用bash脚本做git clone的。
更新
这是我的巴什剧本
for repo in $repos
do
git clone $repo /tmp/tmpdir/
# do stuff
当我试图设置一个码头集装箱时,我偶然发现了一些我不知道如何解决、理解或谷歌的东西。
我有一个Dockerfile来运行脚本。Dockerfile的一个层是:
RUN cd /app/spinnaker-1.23.0.27-amd64 && \
printf 'y\nn\n' | sh install_spinnaker.sh
基本上,我从一些GitHub回购复制了这一行。
当我尝试用docker build --tag=app .构建这个Dockerfile时,它将运行install_spinnaker.sh,直到最后,但随后会崩溃:
[Y/n] $ T
在bash中,为什么这样做很好:
$ cat test1.sh
#!/bin/bash
echo "some text" \
"some more text"
$ ./test1.sh
some text some more text
但这是失败的
$ cat test2.sh
#!/bin/bash
text="some text" \
"some more text"
echo $text
$ ./test2.sh
./test2.sh: line 3: some more text: command not found
我原
为什么在这个脚本的输出中没有发生倾斜扩展?
#!/bin/bash
read -p "Enter filename: " fname
if [[ -d $fname ]]
then
echo "$fname is a directory"
else
echo "$fname is not a directory"
fi
输出:
$ bash -x test_cd.sh
+ read -p 'Enter filename: ' fname
Enter filename: ~/Music
+ [[
我的bash脚本
#!/bin/bash
read -r -p "Enter the filenames: " -a arr
for i in "${arr[@]}"
do
echo $i | sed 's/\(.*\)\..*/\1/'
cp -v ~/Desktop/library/template.py "$i".py
done
如果我编写A B.py C D.py,这个脚本将把它转换为cp -v的A.py B.py C.py D.py -v标志,说明正在做什么。
但是我不想打印编辑的文件名echo $i。这