bash

How to pass backslashes argument to a script?

可紊 提交于 2021-02-10 23:28:58
问题 I just want to append an user input argument in a text file. I'm using the following command: echo "$2" >> "./db.txt" $2 is expected to user to set a path like: D:\Projects\MyProject . It writes to the file, but with no backslashes. The result is: D:ProjectsMyProject I can't find anywhere how to fix that. I've tried using -e or -E params(taken from here) but it doesn't seems to make difference in this case. 回答1: You have to escape backslashes in the shell: \\ , or put the string in quotes.

How to pass backslashes argument to a script?

跟風遠走 提交于 2021-02-10 23:26:25
问题 I just want to append an user input argument in a text file. I'm using the following command: echo "$2" >> "./db.txt" $2 is expected to user to set a path like: D:\Projects\MyProject . It writes to the file, but with no backslashes. The result is: D:ProjectsMyProject I can't find anywhere how to fix that. I've tried using -e or -E params(taken from here) but it doesn't seems to make difference in this case. 回答1: You have to escape backslashes in the shell: \\ , or put the string in quotes.

bash - Capture exit code from remote ssh command

六眼飞鱼酱① 提交于 2021-02-10 23:18:32
问题 I'm looking at capturing the exit status of a remote ssh command within a shell script I have a shell script as follows : function rSSH { local x echo "Running ssh command" x=$(ssh -o StrictHostKeyChecking=no -i $keyPair -o ProxyCommand="ssh -W %h:%p -i $keyPair user@$bastionIP 22" user@$IP "$cmd") x=$? echo "SSH status is : $x" if [ $x -eq 0 ];then echo "Success" else echo "Failure" exit 1 fi } rSSH exit 0 When I execute the above script as a background job with an invalid $bastionIP(

linux - shellscript - “$#” [duplicate]

百般思念 提交于 2021-02-10 22:31:02
问题 This question already has answers here : What does the $# construct mean in bash? [duplicate] (3 answers) Closed 5 years ago . I have a shellscript with the following lines: set -o nounset set -o errexit set -o xtrace if [ "$#" -ne 0 ] then echo 'A message' exit 1 fi Can somebody explain the commands, in particular the setter and the "$#" portion? 回答1: $# is the number of arguments passed to the script. So this if [ "$#" -ne 0 ] check ensures that if no arguments are passed then the script

linux - shellscript - “$#” [duplicate]

眉间皱痕 提交于 2021-02-10 22:27:37
问题 This question already has answers here : What does the $# construct mean in bash? [duplicate] (3 answers) Closed 5 years ago . I have a shellscript with the following lines: set -o nounset set -o errexit set -o xtrace if [ "$#" -ne 0 ] then echo 'A message' exit 1 fi Can somebody explain the commands, in particular the setter and the "$#" portion? 回答1: $# is the number of arguments passed to the script. So this if [ "$#" -ne 0 ] check ensures that if no arguments are passed then the script

linux - shellscript - “$#” [duplicate]

送分小仙女□ 提交于 2021-02-10 22:26:30
问题 This question already has answers here : What does the $# construct mean in bash? [duplicate] (3 answers) Closed 5 years ago . I have a shellscript with the following lines: set -o nounset set -o errexit set -o xtrace if [ "$#" -ne 0 ] then echo 'A message' exit 1 fi Can somebody explain the commands, in particular the setter and the "$#" portion? 回答1: $# is the number of arguments passed to the script. So this if [ "$#" -ne 0 ] check ensures that if no arguments are passed then the script

run command until successful n times bash

人盡茶涼 提交于 2021-02-10 20:51:58
问题 I want to run a command n number of times if it returns unsuccessful I have started with the below loop until find . -type f -exec md5sum {} \; do <something > done I want to run the about n times before it goes continues to the next file Not sure how I can continue from here. I have tried using the return variable $? and looping using this but had no luck Also how could I use the above loop or what is proposed here to put the output of the find into a variable thanks Let me make this abit

run command until successful n times bash

五迷三道 提交于 2021-02-10 20:51:49
问题 I want to run a command n number of times if it returns unsuccessful I have started with the below loop until find . -type f -exec md5sum {} \; do <something > done I want to run the about n times before it goes continues to the next file Not sure how I can continue from here. I have tried using the return variable $? and looping using this but had no luck Also how could I use the above loop or what is proposed here to put the output of the find into a variable thanks Let me make this abit

docker快速部署mysql

☆樱花仙子☆ 提交于 2021-02-10 20:51:26
[toc] docker快速部署mysql 拉取mysql镜像 docker pull mysql:8.0 docker pull mysql:5.7 针对上面不同版本,只需要将对应的版本调整下即可 第一种 mysql docker run -di --restart=always --name=mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0 第二种 mysql docker run -di --restart=always -p 3306:3306 --name mysql \ -v /usr/local/docker/mysql/conf:/etc/mysql \ -v /usr/local/docker/mysql/logs:/var/log/mysql \ -v /usr/local/docker/mysql/data:/var/lib/mysql \ -v /usr/local/docker/mysql/mysql-files:/var/lib/mysql-files \ -e MYSQL_ROOT_PASSWORD=123456 \ -d mysql:8.0 mysql安装之后 docker ps -a 查找到容器id docker exec -it id /bin/bash 进入mysql容器

run command until successful n times bash

百般思念 提交于 2021-02-10 20:51:21
问题 I want to run a command n number of times if it returns unsuccessful I have started with the below loop until find . -type f -exec md5sum {} \; do <something > done I want to run the about n times before it goes continues to the next file Not sure how I can continue from here. I have tried using the return variable $? and looping using this but had no luck Also how could I use the above loop or what is proposed here to put the output of the find into a variable thanks Let me make this abit