-
Notifications
You must be signed in to change notification settings - Fork 0
/
call_rename_script
executable file
·124 lines (105 loc) · 2.63 KB
/
call_rename_script
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
#
# @author Zeus Intuivo <[email protected]>
#
# check to see if I used a message, then it will behave as a put
#bash shell script check input argument
# set working directory as the scripts location during the execution of script
# cd "$(dirname "$0")"
# Bash: Detect pipe/file input in a shell script
# REF: https://gist.github.com/davejamesmiller/1966557
# How to detect whether input is from keyboard, a file, or another process.
# Useful for writing a script that can read from standard input, or prompt the
# user for input if there is none.
# Source: http://www.linuxquestions.org/questions/linux-software-2/bash-scripting-pipe-input-to-script-vs.-1-570945/
PIPED="";
# In Bash you can also use test -t to check for a terminal:
if [ -t 0 ]; then
# Terminal input (keyboard) - interactive
PIPED=""
else
# File or pipe input - non-interactive
PIPED="YES"
fi
# Piped Input
#if [ ! -z "$PIPED" ]
# then
# echo "this is pipe..die "
# exit 0;
#fi
# NOT Piped Input
#if [ -z "$PIPED" ]
# then
# echo "this NOT pipe..die "
# exit 0;
#fi
#echo "PIPED:$PIPED";
#exit;
# ALTERNATIVE:
#if readlink /proc/$$/fd/0 | grep -q "^pipe:"; then
# Pipe input (echo abc | myscript)
# PIPED="YES"
#elif file $( readlink /proc/$$/fd/0 ) | grep -q "character special"; then
# Terminal input (keyboard)
# PIPED=""
#else
# File input (myscript < file.txt)
# PIPED=""
#fi
# CURRENT SCRIPT EXECUTING
THISSCRIPTNAME=`basename "$0"`
# echo "Called $1, $2, $3"
# exit 0
#bash shell script check input argument
FAIL=0;
# echo " ";
if [ -z "$1" ] && [ -z "$PIPED" ] ; then
{
echo "Missing 1st argument "
FAIL=1;
}
fi
if [ "$1" == "-h" ] && [ -z "$PIPED" ] ; then
{
echo "Help "
echo " "
FAIL=1;
}
fi
if [ -z "$2" ] ; then
{
echo "Missing 2nd argument "
FAIL=1;
}
fi
if [ -z "$3" ] && [ "$1" != "-h" ] ; then
{
echo "Missing 3rd argument "
FAIL=1;
}
fi
if [ $FAIL -eq 1 ] ; then
{
echo " ${THISSCRIPTNAME} - Used to call renamescript "
echo " "
echo " Examples: "
echo " "
echo " EXTENSION: js es6 js/cards.js "
echo " "
echo " # The find all the scripts with .js "
echo " # Resulting in: al scripts found renamed to .es6 filename and all references to it also"
echo " "
echo " Sample Usage: - expects three arguments "
echo " "
echo " ${THISSCRIPTNAME} js es6 js/cards.js "
echo " ";
exit 1;
}
fi
fromext="$1"
toext="$2"
from="$3"
# echo "Called $fromext, $toext, $from"
newname=$(echo "$from" | sed -e s@"$fromext"@"$toext"@g)
# echo "Called $from to $newname"
renamescript "$from" "$newname"