sh

How to change current working directory inside command_not_found_handle

ⅰ亾dé卋堺 提交于 2019-12-05 16:05:14
I'm trying to write a not found handle in Bash that does the following: If $1 exists and it's a directory, cd into it. If $1 exists inside a user defined directory $DEV_DIR , `cd into it. If the previous conditions don't apply, fail. Right now I have something like this: export DEV_DIR=/Users/federico/programacion/ function command_not_found_handle () { if [ -d $1 ]; then # the dir exists in '.' cd $1 else to=$DEV_DIR$1 if [ -d $to ]; then cd $to echo `pwd` else echo "${1}: command not found" fi fi } And although it seems to be working (the echo pwd command prints the expected dir), the

msysgit sh.exe arguments

依然范特西╮ 提交于 2019-12-05 15:02:33
问题 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. 回答1: > .\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

Run Jupyter Notebook in the Background on Docker

◇◆丶佛笑我妖孽 提交于 2019-12-05 04:14:38
I am trying to run a jupyter notebook in the background without printing anything to the console. I found this solution in a question for bash: jupyter notebook &> /dev/null & But I am running jupyter in a docker container and want it to start in the background via CMD . How can I do the same in sh? I got it to work using the setup from: https://github.com/jupyter/docker-stacks/tree/master/minimal-notebook the trick was to install tini and put the following code into a start-notebook.sh script: #!/bin/bash exec jupyter notebook &> /dev/null & this is than added to the path with: COPY start

pid=`cat $pidfile` or read pid <$pidfile?

强颜欢笑 提交于 2019-12-05 03:43:54
I read a lot of init.d scripts and: pid=`cat $pidfile` lines make me sad. I don't understand why people doesn't use: read pid <$pidfile Last sample uses POSIX compliant syntax and doesn't do fork / exec to run external process ( cat ). Last solution also allow skipping content after first newline. Are there any traps with read command (despite that it perform splitting into fields)? UPDATE . Some peole use non-portable extension for shell like: How to get variable from text file into Bash variable pid=$(<$pidfile) The read pid < file way is the Best Practice for the reason you stated: much

How to export a function in Bourne shell?

我的梦境 提交于 2019-12-05 03:27:36
Is it possible to export a function in Bourne shell (sh)? The answers in this question indicate how to do so for bash , ksh and zsh , but none say whether sh supports it. If sh definitely does not allow it, I won't spend any more time searching for it. No, it is not possible. The POSIX spec for export is quite clear that it only supports variables. typeset and other extensions used for the purpose in more recent shells are just that -- extensions -- not present in POSIX. No. The POSIX specification for export lacks the -f present in bash that allows one to export a function. A (very verbose)

Dockerfile: how to set env variable from file contents

我的梦境 提交于 2019-12-05 02:31:35
问题 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

Shellwords.shellescape implementation for Ruby 1.8

六眼飞鱼酱① 提交于 2019-12-05 01:30:02
问题 While the build of 1.8.7 I have seems to have a backported version of Shellwords::shellescape , I know that method is a 1.9 feature and definitely isn't supported in earlier versions of 1.8. Does anyone know where I can find, either in Gem form or just as a snippet, a robust standalone implementation of Bourne-shell command escaping for Ruby? 回答1: You might as well just copy what you want from shellwords.rb in the trunk of Ruby's subversion repository (which is GPLv2'd): def shellescape(str)

Bash script fails when running command with embedded quotes (source parameters)

一个人想着一个人 提交于 2019-12-04 22:55:07
I'm using source to insert generated variables into a string from a file in order to execute that string from a bash script. I've echoed the generated string to compare to one that works from the command line and I can't seem to see any difference, but the bash command fails as it seems the supplied parameters are getting mixed up somewhere in the middle. I've escaped double quotes around the ice_name string, so it looks identical to the one that works when I echo it Do I need to escape other characters? It seems to be getting mixed up BEFORE the -ice_name parameter This is the command avconv

What is the intended effective ordering of `set -o` options in bash? Does `histexpand` trump `posix`?

久未见 提交于 2019-12-04 21:49:38
问题 I attempted to answer a question a couple hours ago which I believed revealed a somewhat obscure bug in bash POSIX mode. I was hastily and vehemently told this was not so. The contradicting answer, which explicitly says this is not a bug, was selected as the correct answer. So I've been combing over the bash documentation, and I'm still coming away with very much the same impression, so I thought I should ask. My (alleged) bug: set -o histexpand (which is typically implicit) set -o posix echo

Bash shell: How to check for specific date format?

末鹿安然 提交于 2019-12-04 19:27:07
I have a Bash shell script which checks to see if a shell variable contains a number: if ! [[ "$step" =~ ^[0-9]+$ ]] then exec >&2; echo "error: $step is Not a step number."; exit 1 fi Now I need to do a similar check to see if a variable contains the date in the required format which is YYYY-MM-DD (example: today is 2013-05-13) with the dashes. How can this be done with a regular expression in Bash shell or do I need an external program to do this? regex is not the right tool to do the job. e.g. 2013-02-29 (invalid date) 2012-02-29 (valid date) 2013-10-31 (valid date) 2013-09-31 (invalid date