sh

How do i store the output of a bash command in a variable? [duplicate]

雨燕双飞 提交于 2019-12-04 04:19:37
问题 This question already has answers here : How do I set a variable to the output of a command in Bash? (14 answers) Closed 5 years ago . I'm trying to write a simple script for killing a process. I've already read Find and kill a process in one line using bash and regex so please don't redirect me to that. This is my code: LINE=$(ps aux | grep '$1') PROCESS=$LINE | awk '{print $2}' echo $PROCESS kill -9 $PROCESS I want to be able to run something like sh kill_proc.sh node and have it run kill

POSIX shell equivalent to <()

十年热恋 提交于 2019-12-04 03:06:58
问题 <(commands ...) in bash/zsh makes the output behavior as a file. Does a POSIX equivalent exist? 回答1: mkfifo foo.fifo ## if your "commands" is multiple commands # { commands ...; } >foo.fifo & # otherwise, if it's just one commands ... >foo.fifo & something_else foo.fifo is the closest available equivalent to something_else <( commands ... ) 来源: https://stackoverflow.com/questions/38796224/posix-shell-equivalent-to

msysgit sh.exe arguments

Deadly 提交于 2019-12-04 00:50:44
I am trying to find some documentation about msysgit sh.exe command. For instance I am aware of the --login flag to launch a git bash session but I would to know the other possibilities. I have looked over the internet but can not find any place where is listed all the possibles arguments. poke > .\sh.exe --help GNU bash, version 3.1.0(1)-release-(i686-pc-msys) Usage: ".../Git/bin/sh.exe" [GNU long option] [option] ... ".../Git/bin/sh.exe" [GNU long option] [option] script-file ... GNU long options: --debug --debugger --dump-po-strings --dump-strings --help --init-file --login --noediting -

git - checkout single file under bare repository

我的未来我决定 提交于 2019-12-04 00:31:14
On the server I have bare repository which is origin for development process and to simplify deployment to QA environment. So in post-receive it simply does GIT_WORK_TREE=/home/dev git checkout -f But as product gets more complicated there are some other things should be happening. So now it is handled by deploy.sh script which is also tracked by repository. So what I want to do is to be able instead of checking out whole repository is to checkout only deploy.sh and run it. I thought something like that would work: SOURCE_PATH="/home/dev" GIT_WORK_TREE=$SOURCE_PATH git checkout deploy.sh

Why would I create an alias which creates a function?

两盒软妹~` 提交于 2019-12-03 22:27:36
I see this pattern every once in a while, especially in questions about Bash prompt customization. alias f='_ () { useful code; }; _' I can see no reason at all to create an alias here. The obvious refactoring f () { useful code; } which avoids declaring an alias altogether, and simply defines the function once and for all, seems simpler, more understandable, less brittle, and more efficient. (In case it's not obvious, the alias ends up redeclaring the function every time you invoke the alias.) For example, Make a Bash alias that takes a parameter? has several answers which exhibit this

Is command substitution $(foo) bashism?

て烟熏妆下的殇ゞ 提交于 2019-12-03 18:00:23
问题 There are two different syntaxes for command substitution, FOO=$(echo bar) and FOO=`echo bar` As far as I know, the first method is defined in Bash, while the second is defined in sh . Consider the following use of command substitution in an sh script. #!/bin/sh FOO=$(echo bar) Does that fall under the definition of bashism? bashisms, i.e. features not defined by POSIX (won't work in dash, or general /bin/sh). 回答1: It's the same thing. So no it's not a bashism nor related to bash only.

Dockerfile: how to set env variable from file contents

早过忘川 提交于 2019-12-03 17:06:22
I want to set an environment variable in my Dockerfile. I've got a .env file that looks like this: FOO=bar . Inside my Dockerfile, I've got a command that parses the contents of that file and assigns it to FOO. RUN 'export FOO=$(echo "$(cut -d'=' -f2 <<< $(grep FOO .env))")' The problem I'm running into is that the script above doesn't return what I need it to. In fact, it doesn't return anything. When I run docker-compose up --build , it fails with this error. The command '/bin/sh -c 'export FOO=$(echo "$(cut -d'=' -f2 <<< $(grep FOO .env))")'' returned a non-zero code: 127 I know that the

How to exclude a list of full directory paths in find command on Solaris

爷,独闯天下 提交于 2019-12-03 16:19:37
I have a very specific need to find unowned files and directories in Solaris using a script, and need to be able to exclude full directory paths from the find because they contain potentially thousands of unowned files (and it's normal because they are files hosted on other servers). I don't even want find to search in those directories as it will hang the server (cpu spiking to 99% for a long time), therefore piping the find results in egrep to filter out those directories is not an option. I know I can do this to exclude one of more directories by name: find / -mount -local \( -type d -a \(

Getting user input after stdin has been redirected, in a bourne script

无人久伴 提交于 2019-12-03 16:14:12
(this is indirectly a part of a much larger homework assignment) I have something like while read LINE do stuff-done-to-$LINE echo "Enter input:" read INPUT stuff-done-to-$INPUT done &lt infile I can't find a successful way of using the console/default stdin for the second read, instead of the redirected stdin. Needs to be pure bourne script. I believe this is supported in the Bourne shell: exec 3<doc.txt while read LINE <&3 do stuff-done-to-$LINE # the next two lines could be replaced by: read -p "Enter input: " INPUT echo "Enter input:" read INPUT stuff-done-to-$INPUT done < infile Input is

Jenkins does not recognize command sh?

大城市里の小女人 提交于 2019-12-03 16:06:42
问题 I've been having a lot of trouble trying to get a Jenkinsfile to work. I've been trying to run this test script: #!/usr/bin/env groovy node { stage('Build') { echo 'Building....' // Create virtualenv sh 'echo "hi"' } stage('Test') { echo 'Building....' } stage('Deploy') { echo 'Deploying....' } } But I keep getting this error when trying to build: Warning: JENKINS-41339 probably bogus PATH=/usr/lib64/ccache:/usr/lib64/ccache:$PATH; perhaps you meant to use ‘PATH+EXTRA=/something/bin’? [test