-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand-info.sh
More file actions
executable file
·57 lines (41 loc) · 1.59 KB
/
Copy pathcommand-info.sh
File metadata and controls
executable file
·57 lines (41 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
#This function picks a command randomly from the command array
generate_new_command(){
#Generate a random number between 0 and noOfCommands
randomNumber=$(($RANDOM%noOfCommands))
#the random new Command
newCommand=${commandArray[randomNumber]}
}
#This function extracts info from man page and prints it
manedit() {
#Extract name section from man page
name_sec=`man "$newCommand" |col -bx|awk -v S="NAME" '$0 ~ S{cap="true";} $0 !~ S && /^[A-Z ]+$/ {cap="false"} $0 !~ S && !/^[A-Z ]+$/ {if(cap == "true")print}'| head -5`
#Extract two lines of description from man page
desc_sec=`man "$newCommand" |col -bx|awk -v S="DESCRIPTION" '$0 ~ S {cap="true";} $0 !~ S && /^[A-Z ]+$/ {cap="false"} $0 !~ S && !/^[A-Z ]+$/ {if(cap == "true")print}'|awk -vRS="." 'NR<=2' ORS="."| head -5 `
#Print italic date
echo -e "\e[1;3m\e[1;38m `date`\e[0m"
#Print the command
echo -e "\n\e[1;37m Let's have a look at\e[1;5m\e[1;39m $newCommand \e[0m\n"
#Print the name Section
echo -e "\e[1;35m$name_sec\n"
#Print description
echo -e "\e[1;47m\e[1;4m\e[1;31m Description \e[0m\n"
echo -e "\e[1;36m$desc_sec \e[0m\n"
}
#command holds the list of files present in /usr/bin as string
command=`ls /usr/bin`
#Split the single string to an array{commandArray} containing list of files
commandArray=(${command})
#noOfCommands to hold the length of the array
noOfCommands=${#commandArray[@]}
generate_new_command
`man $newCommand&>/dev/null`
status=$?
#Loop till man page exists for newCommand
while test $status -ne 0
do
generate_new_command
`man $newCommand&>/dev/null`
status=$?
done
manedit