sh
Python process launching
sh 1.11 — sh 1.11 documentation
I have a problem with echo
in my script:
echo -n "Some string..."
prints
-n Some string...
and moves to the next line. In the console it's working correcly without newline:
Some string...
Source: (StackOverflow)
I want to execute mongo commands in shell script.
I tried following way test.sh
#!/bin/sh
mongo myDbName
db.mycollection.findOne()
show collections
When I execute above script ./test.sh
Then mongo connection established but next commands not executed
How to execute other commands through sh script [test.sh] ?
Please help me
Source: (StackOverflow)
I am trying to create an alias that uses both multiple git commands and positional parameters. There are stackoverflow pages for each, and it would appear painfully obvious to do both, but I am having trouble.
As an example, I want to switch to branch foo and perform a status. So in my .gitconfig
, I have:
[alias]
chs = !sh -c 'git checkout $0 && git status'
which doesn't work. Whereas something like this will work.
chs = !sh -c 'git checkout $0'
echoes = !sh -c 'echo hi && echo bye'
Any insight would be appreciated.
Thanks!
Source: (StackOverflow)
To clarify, I am looking for a way to perform a global search and replace on the previous command used. ^word^replacement^
only seems to replace the first match.
Is there some set
option that is eluding me?
Source: (StackOverflow)
I wrote two shell scripts a.sh and b.sh. In a.sh and b.sh I have a infinite for loop and they print some output to the terminal. I want to write another script which calls both a.sh and b.sh but I want the user to regain control of the terminal immediately, instead of having the script run infinitely and I want to hide the output in terminal.
Source: (StackOverflow)
How do I write a script to determine if a file is older than 30 minutes in /bin/sh?
Unfortunately does not stat exist in the system. It is an old Unix system, http://en.wikipedia.org/wiki/Interactive_Unix
Perl is unfortunately not installed on the system and the customer does not want to install it, and nothing else either.
Source: (StackOverflow)
I tried to declare a boolean variable in a shell script using the following syntax:
variable=$false
variable=$true
Is this correct? Also, if I wanted to update that variable would I use the same syntax? Finally, is the following syntax for using boolean variables as expressions correct:
if [ $variable ]
if [ !$variable ]
Source: (StackOverflow)
This seems like such a simple question I'm embarrassed to ask it:
test.sh
#!/bin/bash
STR = "Hello World"
echo $STR
when I run sh test.sh I get this:
test.sh: line 2: STR: command not found
What am I doing wrong? I look at extremely basic/beginners bash scripting tutorials online and this is how they say to declare variables... So I'm not sure what I'm doing wrong.
I'm on Ubuntu Server 9.10. And yes, bash is located at /bin/bash
.
Source: (StackOverflow)
On Linux, the readlink
utility accepts an option -f
that follows additional links. This doesn't seem to work on Mac and possibly BSD based systems. What would the equivalent be?
Here's some debug information:
$ which readlink; readlink -f
/usr/bin/readlink
readlink: illegal option -f
usage: readlink [-n] [file ...]
Source: (StackOverflow)
readlink -f
does not exist on MacOS. The only working solution for Mac OS I managed to find on the net goes like this:
if [[ $(echo $0 | awk '/^\//') == $0 ]]; then
ABSPATH=$(dirname $0)
else
ABSPATH=$PWD/$(dirname $0)
fi
Can anyone suggest anything more elegant to this seemingly trivial task?
Source: (StackOverflow)
I have a file f1
:
line1
line2
line3
line4
..
..
I want to delete all the lines which are in another file f2
:
line2
line8
..
..
I tried something with cat
and sed
, which wasn't even close to what I intended. How can I do this?
Source: (StackOverflow)
In sh/ksh/bash to store the output of a command as a variable you can do either
MY_VAR=$(command)
#or you can do
MY_VAR=`command`
What's the difference if any between the two methods?
Source: (StackOverflow)
I'm looking for shell script that merge files from one directory into another.
Sample:
html/
a/
b.html
index.html
html_new/
a/
b2.html
b.html
Usage:
./mergedirs.sh html html_new
Result:
html/
a/
b.html
b2.html
index.html
html/a/b.html
was replaced by html_new/a/b.html
html/a/b2.html
was copied to html_new/a/b2.html
html/index.html
kept untouched
Source: (StackOverflow)
I was going through some shell script tutorials and found the following sample program:
#!/bin/sh
clear
echo "HELLO WORLD"
Can anyone please tell what is the significance of mentioning '!/bin/sh' in the comment?
Thanks.
Source: (StackOverflow)