Hot answers tagged

19

That is a documented feature. If you run bash via a symlink named sh, bash will start in sh compatibility mode. From man bash: If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login ...


6

Assuming: the environment variable $NEMO_SCRIPT_SELECTED_FILE_PATHS is somehow magically set for you by nemo, and it contains a newline-separated list of filenames, you can parse it out into a bash array like this: $ NEMO_SCRIPT_SELECTED_FILE_PATHS="file one file two file three" $ mapfile -t files <<<"$NEMO_SCRIPT_SELECTED_FILE_PATHS" $ ...


3

To select any line containing gold from source.txt and replace the first occurrence of green with red: $ sed -n '/gold/{s/green/red/; p}' source.txt gold red white black blue To save that in a file: sed -n '/gold/{s/green/red/; p}' source.txt >pol.txt How it works -n tells sed not to print lines unless we explicitly ask it to. /gold/ selects ...


2

The exit values from your experiment are correct. When the test utility evaluates an expression, if the expression evaluates to true, test returns a zero (true) exit status; otherwise it returns 1 (false). So, in your example, test -L ../Dependencies returns 0 (true) because ../Dependencies is a symbolic link. If ../Dependencies was not a symbolic link, ...


2

As you seem to understand, shell built-in functions such as echo are processed by the running shell and therefore do not require a new process to be started in the foreground (normally). However, if you send them to the background, they need to be controlled by a distinct shell and will consequently start a new shell process with the command in question. ...


2

I do not know any particular method for dry run, but we can use some precautions for understanding an unknown script. Use a chroot environment to run your debug script. It will act as a sandbox and will provide protection against deleting/modifying main system files. Use bash -n <script> for syntax check. From gnu bash manual https://www.gnu.org/...


2

It looks like you need to add that directory to your path. The exact command to do this depends on which shell is in use. For bash, you'll need something like: export PATH=$PATH:/home/user/Downloads/program/ Explanation: The PATH=$PATH keeps the existing path as part of the new path your are creating. The :/home/user/Downloads/program/ adds that ...


1

Solution 1: exec You may place an exec command at the beginning of the script: $ cat script1 #!/bin/bash exec > >(tee file.log) echo one echo two Here is an example of running script1: $ bash script1 $ one two $ Observe that the shell prompt returned before the output from the script was complete. This is because the output went to a ...


1

you can redirect the std(out,err,in) using exec: http://www.tldp.org/LDP/abs/html/x17974.html


1

Ok found the answer. If I place a () in the beginning and end of this it works. (ssh $SERVER "su $ORACLE_USER -c 'export ORACLE_HOME=\"/u01/app/oracle/product/11.2.0\"; export PATH=\"/u01/app/oracle/product/11.2.0/Opatch:\$PATH\"; opatch lsiinventory'") > /tmp/output.txt


1

grep -l "gold" source.txt will output source.txt if the file contains the word gold xargs sed 's/green/red/' will run sed 's/green/red/' source.txt and the final redirect saves the result in your output. If I understand your intent correctly, you want the following command: sed -n '/gold/s/green/red/p' source.txt > pol.txt The /gold/ selects lines ...


1

If your strings are in a file called file: $ sed 's|</td><td><a href="javascript:[^>]*">|;|g' file Central and Western;Kwun Lung Lau Central and Western;The Merton Eastern;Fung Wah Estate Wong Tai Sin;Tsz Oi Court If your string is in a shell variable called s: $ echo "$s" Central and Western</td><td><a href="...


1

You are trying to install the gem using sudo, but the system knows the path for your user but not the for the sudo user. If you already added the following line to your ~/.bashrc: PATH="$(ruby -e 'print Gem.user_dir')/bin:$PATH" You can install your gems without sudo, like this example: gem install sass


1

You could use process substitution, which is more idiomatic and less cumbersome than a named pipe. cat header.sql <(zcat bigfile.gz | tail -n+50)


1

I just wrote this function for the same reason. I never know which shell has admin privileges. function isadmin() { net session > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "admin" else echo "user"; fi } It adapted from this answer http://stackoverflow.com/a/11995662/307968 for windows cmd shell. Net Session returns 0 status if you ...



Only top voted, non community-wiki answers of a minimum length are eligible