Skip to content

Commit 9c84883

Browse files
work with dollar & awk
Signed-off-by: Arnob kumar saha <[email protected]>
1 parent 1aa24f8 commit 9c84883

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

basics/dollar.bash

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
4+
https://stackoverflow.com/questions/5163144/what-are-the-special-dollar-sign-shell-variables#5163260
5+
6+
$1, $2, $3, ... are the positional parameters.
7+
"$@" is an array-like construct of all positional parameters, {$1, $2, $3 ...}.
8+
"$*" is the IFS expansion of all positional parameters, $1 $2 $3 ....
9+
$# is the number of positional parameters.
10+
$- current options set for the shell.
11+
$$ pid of the current shell (not subshell).
12+
$_ most recent parameter (or the abs path of the command to start the current shell immediately after startup).
13+
$IFS is the (input) field separator.
14+
$? is the most recent foreground pipeline exit status.
15+
$! is the PID of the most recent background command.
16+
$0 is the name of the shell or shell script.

common/awk.bash

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# printing first collumn of ps command. 'print $0' & 'print' means all collumn in this case
4+
ps | awk '{print $1}'
5+
6+
7+
# awk -F ":" quoteAndBracket # : is the column seperator
8+
#'{print $1"\t"$4}'
9+
10+
awk 'BEGIN{FS=":"; OFS="-"} {print $1,$4}' /etc/passwd
11+
12+
13+
# ^/ means every line that begins with a slash, \ is used for escaping
14+
awk -F "/" '/^\// {print $NF}' /etc/shells # only last word
15+
16+
17+
df | awk '/\/dev\/loop/ {print $1"\t"$2 + $3}'
18+
19+
awk 'length($0) > 7' /etc/shells
20+
21+
ps -ef | awk '{ if($NF == "/bin/fish") print $0}'
22+
23+
awk 'BEGIN { for(i=1; i<=10; i++) print "sq of ", i, "is", i*i;}'
24+
25+
awk '$1 ~ /^[b,c]/ {print $0}' .bashrc
26+
27+
awk '{print substr($0, 4)}' numbered.txt
28+
29+

tricks.sh

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# AUTHOR : Arnob kumar saha
4+
# Date created : 11-06-2022
5+
# Lase modified : 11-06-2022
6+
7+
# DESCRIPTION : This holds some shortcuts and tricks for terminal usage.
8+
# USAGE : ./tricks.sh
9+
10+
11+
cd - # cd to the prevoius directory
12+
ctrl + L # clear the terminal, scrolling the mouse to above is possible though
13+
14+
pushd <dir> # cd to <dir> & pushes <dir> on a stack, to later cd into that using popd
15+
popd # cd to the stack's top directory & pod that from stack
16+
17+
ctrl + z # suppose you are editing on vim & u for some reason want to go back to your current terminal
18+
# without saving ow quitting the editing file
19+
fg # (foreground) to again get back to editing
20+
21+
sudo !! # exexute the last command with sudo previledges
22+
ctrl + r # search some previous running command from terminal history
23+
24+
HISTTIMEFORMAT="%Y-%m-%d %T " # now `hostory` command will also show you the data-time of the command execution
25+
!<ID from `history` command> # to execute a particular command from history
26+
27+
cmatrix # cool hacker-like background !
28+
ctrl + shift + plusSign # to increase terminal font size
29+
ctrl + minusSign # to decrease
30+
31+
ctrl + a # move cursor on the beginning of the current line
32+
ctrl + e # move cursor on the end of the current line
33+
ctrl + w # delete the last word
34+
ctrl + u # delete the whole line
35+
36+
tail -f <file> # to watch last few lines of a continously-changing file
37+
truncate -s 0 <file> # make this file size 0 (Delete everything from this file)
38+
mount | column -t # 'column' command shows the output in column to look it better
39+
40+
41+

0 commit comments

Comments
 (0)