对于将参数传递给bash中if语句中的函数感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍参数char*如何传参,并为您提供关于Bash–如何将参数传递给通过标准输入读取的脚本、Bash–如何将
对于将参数传递给bash中if语句中的函数感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍参数char*如何传参,并为您提供关于Bash – 如何将参数传递给通过标准输入读取的脚本、Bash – 如何将参数传递给通过重定向标准输入读取的脚本、bash – 如何通过docker运行将参数传递给Shell脚本、bash – 将参数传递给命令时转义字符的有用信息。
本文目录一览:- 将参数传递给bash中if语句中的函数(参数char*如何传参)
- Bash – 如何将参数传递给通过标准输入读取的脚本
- Bash – 如何将参数传递给通过重定向标准输入读取的脚本
- bash – 如何通过docker运行将参数传递给Shell脚本
- bash – 将参数传递给命令时转义字符
将参数传递给bash中if语句中的函数(参数char*如何传参)
#!/bin/bash foo() { if [ $1 = "zero" ]; then echo "0" else echo "1" fi } arg="zero" if foo $arg -eq 0 ; then echo "entered 0" else echo "entered something else" fi arg="blah" if foo $arg -eq 0 ; then echo "entered 0" else echo "entered something else" fi
不是预期的结果:
cknight@macbook:~/work$./test.sh 0 entered 0 1 entered 0
先感谢您.
〜克里斯
if [ $(foo $arg) -eq 0 ] ; then
Bash – 如何将参数传递给通过标准输入读取的脚本
让我们说我有以下几点:
cat script.sh | bash
我如何将参数传递给脚本?
我不想这样做:
bash script.sh arguments
也不是:
./script.sh arguments
cat script.sh | bash /dev/stdin arguments
似乎工作
Bash – 如何将参数传递给通过重定向标准输入读取的脚本
我想创建一个脚本,它采用标准输入,并在传递参数的同时远程运行它.
我正在建立的脚本的简化内容:
ssh server_name bash <&0
如何采取以下接受参数的方法并将其应用于我的脚本?
cat script.sh | bash /dev/stdin arguments
也许我这样做不正确,请提供替代解决方案.
cat script.sh | ssh some_server bash -s - <arguments>
bash – 如何通过docker运行将参数传递给Shell脚本
例如:我的shell脚本看起来像:
#!bin/bash echo $1
Dockerfile如下所示:
FROM ubuntu:14.04 copY ./file.sh / CMD /bin/bash file.sh
我不知道如何在运行容器时传递参数
把arg1直接放到Dockerfile中,是你的请求吗?
这是我的答案
更新file.sh
#!/usr/bin/env bash echo $1
使用存在的Dockerfile
构建形象:
docker build -t test .
用参数abc或xyz或其他东西运行图像.
docker run -ti test /file.sh abc docker run -ti test /file.sh xyz
bash – 将参数传递给命令时转义字符
我经常使用我的Android手机将音频文件录制到手机的内部存储器中.我想编写一个Bash脚本来从手机中提取最新录制的文件并将其移动到我的桌面.这是我到目前为止所得到的:
adb shell find /storage/sdcard0/Sound\ Recordings/ | tail -1 | while read file ; do
adb pull "$file" ~/Desktop/
done
但是,这失败了.似乎ADB没有正确地逃避事情,我在尝试运行脚本时收到以下消息:
' does not existstorage/sdcard0/Sound Recordings/20120817T065953.wav
它似乎忽略了双引号,当它试图运行时,一切基本上都会中断,因为它可能看到3个参数而不是两个,类似这样:
adb pull /storage/sdcard0/Sound Recordings/20120817T065953.wav ~/Desktop/
如何调整我的脚本以在必要时将反斜杠插入到我的$file变量中?在这种情况下,这是正确的解决方案吗?
解决方法:
由于您在另一个shell级别运行它,因此它会在子shell中运行之前进行扩展.解决此问题的最简单方法是转义文件名中的任何特殊字符:
adb shell find /storage/sdcard0/Sound\ Recordings/ | tail -1 | while IFS= read -r file ; do
adb pull "$(printf %q "$file")" ~/Desktop/
done
今天的关于将参数传递给bash中if语句中的函数和参数char*如何传参的分享已经结束,谢谢您的关注,如果想了解更多关于Bash – 如何将参数传递给通过标准输入读取的脚本、Bash – 如何将参数传递给通过重定向标准输入读取的脚本、bash – 如何通过docker运行将参数传递给Shell脚本、bash – 将参数传递给命令时转义字符的相关知识,请在本站进行查询。
本文标签: