- Details
- Written by: Stanko Milosev
- Category: Linux
- Hits: 8247
Few commands which I am using this moment:
top - to display running processes
pgrep chrome | xargs kill - to kill all chrome processes
whereis - locate the binary, source, and manual page files for a command
ifconfig - I am using this command to get my IP address
- Details
- Written by: Stanko Milosev
- Category: Linux
- Hits: 9938
Copy paste from here:
The vertical bar character is used to represent a pipe in commands in Linux and other Unix-like operating systems. A pipe is a form of redirection that is used to send the output of one program to another program for further processing.
Example which I use to kill all chrome instances:
- Details
- Written by: Stanko Milosev
- Category: Linux
- Hits: 8817
Just few things which I learned.
Array:
myList="a b c d";
myListAry=${myList[@]}
for my in $myListAry; do
echo $my;
done
No spaces at sign of equality when assigning a value to variable.
Instead of quotes you can use parentheses also, but in that case I was receiving some stupid error from Grunt:
Syntax error: "(" unexpected (expecting "}")
Also, in my case this example also works (without array):
myList="a b c d";
for my in $myList; do
echo $my;
done
I had to do it without converting to array, because in the Grunt I was receiving error:
"Bad substitution"
Those two examples you can download from here. To test it, save it in a folder, lets say in Downloads, go to that folder:
cd Downloads
Load file:
. ./bash.sh
execute either:
exampleWithoutArray
or:
exampleWithArray
To replace string in a (same) file:
sed -i.bak 's/"'$my'"/"someString"/g' /home/stanko/someFile.txt
Notice that I was using double quotes, because lets assume that in your file you want "someString" replace with my variable but to have quotes. Under single quotes dollar sign ($) is not recognized, that is why I had to "close" quotes.
Switch -i means that I want to replace string in a same file.
Also, when I was loading bash script from terminal window, it seems that variables are populated like global, just once and never again, that is why I had to close terminal window, open it again, and again to load my script, otherwise my changes inside of variables would not be visible....
To comment block, use something like this:
#!/bin/bash
echo before comment
: <<'END'
bla bla
blurfl
END
echo after comment
Copy/pasted from here.