-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse_stdin.sh
More file actions
56 lines (44 loc) · 2.44 KB
/
reverse_stdin.sh
File metadata and controls
56 lines (44 loc) · 2.44 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
#!/usr/bin/env bash
# this script accepts a parameter ($1) to reverse, if $1 is empty, it will be assigned the value of /dev/stdin (standard input)
# for more information see: (source) https://stackoverflow.com/questions/6980090/how-to-read-from-a-file-or-standard-input-in-bash and
# https://stackoverflow.com/questions/11461625/reverse-the-order-of-characters-in-a-string
# Customized by: istackz
# while loop to accept/prompt for input
while read "Enter input: " INPUT
do
# variables
VAR=$INPUT;
COPY=$VAR;
LEN=${#VAR};
# for loop to reverse user input
for (( i=LEN - 1; i >= 0; i-- ))
do
REV="$REV${COPY:$i:1}";
done
# print message
echo -e "\nYou've provided $VAR as input.\n";
echo -e "\nReverse Input: $REV\n";
done < "${1:-/dev/stdin}":
# Note: the line "${1:-/dev/stdin}" is used to assign the value of $1 to the variable VAR. If $1 is empty, then it will be assigned the value of /dev/stdin (standard input).
#############
# my banner #
#############
##########################################################
# source: http://patorjk.com/software/taag/ #
##########################################################
echo -e "\nScript by: ";
echo -e "\n";
echo -e "\e[5;32m";
echo -e " ██▓ ██████▄▄▄█████▓▄▄▄ ▄████▄ ██ ▄█▒███████▒";
echo -e "▓██▒██ ▒▓ ██▒ ▓▒████▄ ▒██▀ ▀█ ██▄█▒▒ ▒ ▒ ▄▀░";
echo -e "▒██░ ▓██▄ ▒ ▓██░ ▒▒██ ▀█▄ ▒▓█ ▄▓███▄░░ ▒ ▄▀▒░ ";
echo -e "░██░ ▒ ██░ ▓██▓ ░░██▄▄▄▄██▒▓▓▄ ▄██▓██ █▄ ▄▀▒ ░";
echo -e "░██▒██████▒▒ ▒██▒ ░ ▓█ ▓██▒ ▓███▀ ▒██▒ █▒███████▒";
echo -e "░▓ ▒ ▒▓▒ ▒ ░ ▒ ░░ ▒▒ ▓▒█░ ░▒ ▒ ▒ ▒▒ ▓░▒▒ ▓░▒░▒";
echo -e " ▒ ░ ░▒ ░ ░ ░ ▒ ▒▒ ░ ░ ▒ ░ ░▒ ▒░░▒ ▒ ░ ▒";
echo -e " ▒ ░ ░ ░ ░ ░ ▒ ░ ░ ░░ ░░ ░ ░ ░ ░";
echo -e " ░ ░ ░ ░ ░ ░ ░ ░ ░ ";
echo -e " ░ ░ ";
echo -e "\e[0m";
echo -e "\n";
###########################################################