- Details
- Written by: Stanko Milosev
- Category: Linux
- Hits: 10084
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: 8898
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.
- Details
- Written by: Stanko Milosev
- Category: Linux
- Hits: 1068
Example of generatin
- Details
- Written by: Stanko Milosev
- Category: Ubuntu
- Hits: 26402
To write this article I am using this web site.
Open Gedit, and while Gedit window is active go to Edit -> Preferences:
Go to plugins and check external tools:
Now open Manage External Tools:
Click add:
Enter a name (Format JSON), paste this text:
#! /usr/bin/env python
import json
import sys
j = json.load(sys.stdin)
print json.dumps(j, sort_keys=True, indent=2)
Set Input to Current document and set Output to Replace current document: