sh

How should a backslash resulting from variable expansion be treated?

北城以北 提交于 2019-12-22 08:35:28
问题 I ran the following command ( *sh being the name of a sh implementation) with all the shells I could find; although I was expecting all to print match , I got inconsistent results. I don't know which behavior is correct and reliable. *sh -c 'case "$1" in $2) echo match; esac' _ 'f\oo' 'f\\oo' With dash from Ubuntu bionic's repo (and ash; which is a symbolic link to dash) $ dash -c 'case "$1" in $2) echo match; esac' _ 'f\oo' 'f\\oo' match With bash 4.4.20(1)-release (x86_64-pc-linux-gnu) and

Executing .sh scripts via PHP

不羁岁月 提交于 2019-12-22 08:23:16
问题 I have a few game servers that that I need to run shell scripts for frequality. I'm trying to figure out how to run these scripts via a webpage on the same server. It's a Ubuntu Dedicated server. The website files are located via /var/www/... The .sh files I need to manually run are located in /home/amservers/.../start.sh . I've looked at other answers and I still can't figure it out. How do locate the files and store it and then run exec()? 回答1: You could just use the shell_exec() function

Executing .sh scripts via PHP

五迷三道 提交于 2019-12-22 08:22:26
问题 I have a few game servers that that I need to run shell scripts for frequality. I'm trying to figure out how to run these scripts via a webpage on the same server. It's a Ubuntu Dedicated server. The website files are located via /var/www/... The .sh files I need to manually run are located in /home/amservers/.../start.sh . I've looked at other answers and I still can't figure it out. How do locate the files and store it and then run exec()? 回答1: You could just use the shell_exec() function

How to execute the vim commands through shell script

故事扮演 提交于 2019-12-22 05:39:24
问题 Hi I have a situation as I have a writing a shell script where I have to pass input to the vim . Explaining in detail Here I have already written shell script that I cannot changed. Here is the code for it. sudo vim /mnt/etc/{hosts,hostname,ports} due to this hosts file is opened we can go manually next to the hostname file by :n and similar for the ports file. But I have to perform same operation from my .sh file. Also I have to edit the ports file and after completing it I have to save and

Run Jupyter Notebook in the Background on Docker

末鹿安然 提交于 2019-12-22 04:52:55
问题 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? 回答1: 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

How to export a function in Bourne shell?

末鹿安然 提交于 2019-12-22 04:30:18
问题 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. 回答1: 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. 回答2: No. The

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

狂风中的少年 提交于 2019-12-22 04:09:47
问题 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

Why would I create an alias which creates a function?

落花浮王杯 提交于 2019-12-21 06:56:17
问题 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

Detect if stdout is redirected to a pipe (not to a file, character device, terminal, or socket)?

青春壹個敷衍的年華 提交于 2019-12-21 04:26:10
问题 Ideally, this would be scriptable in shell, but Perl or Python would be fine. C code could be helpful, but probably fails cost/benefit. I recognize that redirection to a FIFO (named pipe) may be indistinguishable from a real pipe, and that is enough of an edge case that I don't really care. Strict POSIX solutions are best, UNIX/Linux variant-independent are next best, but at least something that works on Darwin (MacOS X) is what I need right now. Before you write your answer - I already know

git with --git-dir= results in 'not a git repository'

依然范特西╮ 提交于 2019-12-21 03:14:24
问题 I have a script in one of my iOS apps that should get the git revision hash and put it in the version number. In this script I run git --git-dir="$PROJECT_DIR" show -s --pretty=format:%h for that. However, I get the message that the directory isn't a git repository. If I echo the PROJECT_DIR var and go to the terminal the following works: cd projectDirPath git show -s --pretty=format:%h What doesn't work is: git --git-dir=projectDirPath show -s --pretty=format:%h Am I missing something? The