sh

Terminal error: zsh: permission denied: ./startup.sh

眉间皱痕 提交于 2020-03-15 20:49:50
问题 I am running a command ./startup.sh nginx:start and I am getting this error message zsh: permission denied: ./startup.sh why could this be happening? 回答1: Be sure to give it the execution permission. cd ~/the/script/folder chmod +x ./startup.sh 回答2: Alternatively you can use bash: bash startup.sh Then you don't need execution permission. In MacOS Catalina, Apple has replaced bash with zsh as default shell. This can mean, that they intend to remove bash in the future, so this might not be an

Pass commands as input to another command (su, ssh, sh, etc)

限于喜欢 提交于 2020-03-04 21:57:44
问题 I have a script where I need to start a command, then pass some additional commands as commands to that command. I tried su echo I should be root now: who am I exit echo done. ... but it doesn't work: The su succeeds, but then the command prompt is just staring at me. If I type exit at the prompt, the echo and who am i etc start executing! And the echo done. doesn't get executed at all. Similarly, I need for this to work over ssh : ssh remotehost # this should run under my account on

Pass commands as input to another command (su, ssh, sh, etc)

一世执手 提交于 2020-03-04 21:52:50
问题 I have a script where I need to start a command, then pass some additional commands as commands to that command. I tried su echo I should be root now: who am I exit echo done. ... but it doesn't work: The su succeeds, but then the command prompt is just staring at me. If I type exit at the prompt, the echo and who am i etc start executing! And the echo done. doesn't get executed at all. Similarly, I need for this to work over ssh : ssh remotehost # this should run under my account on

Pass commands as input to another command (su, ssh, sh, etc)

余生颓废 提交于 2020-03-04 21:52:04
问题 I have a script where I need to start a command, then pass some additional commands as commands to that command. I tried su echo I should be root now: who am I exit echo done. ... but it doesn't work: The su succeeds, but then the command prompt is just staring at me. If I type exit at the prompt, the echo and who am i etc start executing! And the echo done. doesn't get executed at all. Similarly, I need for this to work over ssh : ssh remotehost # this should run under my account on

How to update bash script whilst running or easily restart it?

会有一股神秘感。 提交于 2020-02-26 03:25:30
问题 I require a method to easily restart/replace bash scripts without manually stopping/starting the process over again. Here's how my current script works: #!/bin/sh while true do echo "1" java -server -Xms2G -jar game.jar nogui done Basically, if the game stops, it will automatically restart however, the script is already loaded into memory so if I was to modify it, I would have to manually kill the script and start it up again in order for the changes to take effect. I'm running at least 200

How to output return code in shell?

依然范特西╮ 提交于 2020-02-18 06:10:29
问题 I'm trying to call a custom shell script through sh : /bin/sh -c 'myscript.sh` >log.txt 2>&1 & echo $! Output of this command is a PID of a created background process. I want to instruct /bin/sh to save return code of myscript.sh to some file. Is it possible? 回答1: (/bin/sh -c "myscript.sh" >log.txt 2>&1 ; echo $? >somefile) & echo $! 回答2: echo $? >> /path/to/return_code $? has the return code of the last statement in bash. 回答3: ( /bin/sh -c 'myscript.sh` >log.txt 2>&1 echo $? > some_file ) &

How to output return code in shell?

点点圈 提交于 2020-02-18 06:03:13
问题 I'm trying to call a custom shell script through sh : /bin/sh -c 'myscript.sh` >log.txt 2>&1 & echo $! Output of this command is a PID of a created background process. I want to instruct /bin/sh to save return code of myscript.sh to some file. Is it possible? 回答1: (/bin/sh -c "myscript.sh" >log.txt 2>&1 ; echo $? >somefile) & echo $! 回答2: echo $? >> /path/to/return_code $? has the return code of the last statement in bash. 回答3: ( /bin/sh -c 'myscript.sh` >log.txt 2>&1 echo $? > some_file ) &

Saving function output into a variable named in an argument

不羁的心 提交于 2020-02-08 10:14:09
问题 I have an interesting problem that I can't seem to find the answer for. I am creating a simple app that will help my dev department auto launch docker containers with NginX and config files. My problem is, for some reason I can't get the bash script to store the name of a folder, while scanning the directory. Here is an extremely simple example of what I am talking about.... #!/bin/bash getFolder() { local __myResultFolder=$1 local folder for d in */ ; do $folder=$d done __myResultFolder=

How to display command output in a whiptail textbox

こ雲淡風輕ζ 提交于 2020-02-04 01:31:29
问题 The whiptail command has an option --textbox that has the following description: --textbox <file> <height> <width> The first option requires a file as input; I would like to use the output of a command in its place. It seems like this should be possible in sh or bash. For the sake of the question, let's say I'd like to view the output of ls -l in a whiptail textbox. Note that process substitution does not appear to work in whiptail (e.g. whiptail --textbox <(ls -l) 40 80 does not work. This

How to iterate over text file having multiple-words-per-line using shell script?

北战南征 提交于 2020-01-30 08:30:25
问题 I know how to iterate over lines of text when the text file has contents as below: abc pqr xyz However, what if the contents of my text file are as below, abc xyz cdf pqr lmn rst and I need to get values "abc" stored to one variable and"xyz" stored to another variable. How would I do that? 回答1: If the delimiter is a space then you can do: #!/bin/bash ALLVALUES=() while read line do ALLVALUES+=( $line ) done < "/path/to/your/file" So after, you can just reference an element by ${ALLVALUES[0]}