shell

Do we have short circuit logical operators in C shell script?

血红的双手。 提交于 2021-02-19 07:23:12
问题 I thought C shell script will behave like C and use short circuit evaluation for logical operators. if ((! -e $cache ) || ("`find $monitor -newer $cache`" != "")) then ... endif But in the if statement, even if the first condition is true, the second is checked giving me errors. Do we have a short circuit logical OR in C shell script? 回答1: Usually, && and || are short-circut. Consider something like this: $ false && echo foo $ true || echo foo In both cases, foo won't be put out. But, AFAIK

How to get lines from the last match to the end of file?

邮差的信 提交于 2021-02-19 06:39:10
问题 Need to print lines after the last match to the end of file. The number of matches could be anything and not definite. I have some text as shown below. MARKER aaa bbb ccc MARKER ddd eee fff MARKER ggg hhh iii MARKER jjj kkk lll Output desired is jjj kkk lll Do I use awk with RS and FS to get the desired output? 回答1: You can actually do it with awk (gawk) without using any pipe. $ awk -v RS='(^|\n)MARKER\n' 'END{printf "%s", $0}' file jjj kkk lll Explanations: You define your record separator

Running Conda commands in NodeJS

余生长醉 提交于 2021-02-19 06:28:07
问题 I can't run a Conda command using exec with my NodeJS app. var conda_path = '~/miniconda3/bin/conda' var cmd = conda_path + ' init bash & ' + conda_path + ' activate XYZ' exec(command, function(error, stdout, stderr){ } ); I get the following error: /bin/sh: /Users/username/Desktop/repos/project/XYZ: is a directory CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'. To initialize your shell, run $ conda init <SHELL_NAME> Currently supported shells are: -

Vim: wrap long :make lines in message dialog?

て烟熏妆下的殇ゞ 提交于 2021-02-19 06:23:06
问题 When executing a :make command that displays its content in a temporary vim buffer, is there any way to have these lines soft-wrapped at the edge of the terminal? Most console hosts do not have side scrolling and any long lines that come out of :make are completely truncated in vim (i.e. expanding the terminal width after-the-fact does not recover them). I'm not able to interact with the buffer containing the :make results in any meaningful way ( :set wrap or zl ) that would allow me to

Call php function from bash - with arguments

余生颓废 提交于 2021-02-19 05:20:25
问题 I have a simple func.php file with concat function: <?php function concat($arg1, $arg2) { return $arg1.$arg2; } ?> I would like to call this function from linux bash shell with two arguments : 1st: "Hello, " 2nd: "World!" and print the output ("Hello, World!") to linux bash shell. Please tell me, how to do it? 回答1: What you want is $argv So for example, your script would be called like this: php /path/to/script.php 'Hello, ' 'World!' Then in your PHP file: <?php $arg1 = $argv[1]; $arg2 =

Is ./*/ portable?

家住魔仙堡 提交于 2021-02-19 04:27:06
问题 I often use ./*/ in a for loop like for d in ./*/; do : # do something with dirs done to match all non-hidden directories in current working directory, but I'm not really sure if this is a portable way to do that. I have bash, dash and ksh installed on my system and it works with all, but since POSIX spec doesn't say anything about it (or it says implicitly, and I missed it) I think I can't rely on it. I also checked POSIX bug reports, but to no avail, there's no mention of it there as well.

Nested while read loops with fd

混江龙づ霸主 提交于 2021-02-19 04:04:13
问题 I'm trying to read from two different inputs in nested loops without success. I've followed the best answer on this question and also took a look at the file descriptors page of the Advanced Bash-Scripting Guide . Sample script I made to test my problem. #!/bin/bash while read line <&3 ; do echo $line while read _line <&4 ; do echo $_line done 4< "sample-2.txt" done 3< "sample-1.txt" Content of sample-1.txt Foo Foo Content of sample-2.txt Bar Bar Expected output Foo Bar Bar Foo Bar Bar The

Shell Expansion (Command substitution) in Golang

孤街浪徒 提交于 2021-02-19 03:53:07
问题 Go has the support for variable expansion , for example: os.ExpandEnv("test- ${USER} ")` >> "test-MyName" But is there a way of expanding executables , as the way the shell behaves? Something like os.ExpandExecutable("test- $(date +%H:%M) ") >> "test-18:20" I cannot find an equivalent method for this, is there an elegant way of doing this instead of manually extracting the placeholders out, executing and then replacing them? 回答1: There's no built in function for this, but you can write a

How can I start and stop a background task on travis?

浪子不回头ぞ 提交于 2021-02-19 01:35:36
问题 I need to start and restart a custom web server on travis. Starting in background is fine using a sub-shell ( .travis.yml ): - if [ "$TEST_ADAPTER" = "HTTP" ]; then (vendor/bin/httpd.php start &); fi To stop/kill the process again I'm trying to get its PID and then kill it: - if [ "$TEST_ADAPTER" = "HTTP" ]; then (vendor/bin/httpd.php start &) && SERVER_PID=$!; fi - ... - if [ "$TEST_ADAPTER" = "HTTP" ]; then kill -9 $SERVER_PID && ...; fi However, SERVER_PID is empty. What is the right way

Python3 Run Alias Bash Commands

你离开我真会死。 提交于 2021-02-18 18:54:37
问题 I have the following code that works great to run the ls command. I have a bash alias that I use alias ll='ls -alFGh' is it possible to get python to run the bash command without python loading my bash_alias file, parsing, and then actually running the full command? import subprocess command = "ls" # the shell command process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None, shell=True) #Launch the shell command: output = process.communicate() print (output[0]) Trying with