-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshebang.sh
More file actions
executable file
·36 lines (32 loc) · 1.07 KB
/
shebang.sh
File metadata and controls
executable file
·36 lines (32 loc) · 1.07 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
#!/bin/sh
# Check if shebang is the first line
# if not add shebang at the beginning of the file
if [ $1 = "-a" ] || [ $1 = "-A" ]
then
echo Scanning all files...
for file in *.sh
do
# echo "First line of: " $file "is: " $(head -n 1 $file)
if [ "$(head -n 1 $file)" != "#!/bin/sh" ]
then
echo "inserting shebang: $file"
$(sed -i '1i #!/bin/sh' $file)
echo "$file $(/usr/bin/printf "\xE2\x9C\x94\n")"
else
echo "$file $(/usr/bin/printf "\xE2\x9C\x94\n")"
fi
done
else
for file in $@ # $@ is a special variable that retrieves all user input from $0 to all the way to the end
do
# echo "First line of: " $file "is: " $(head -n 1 $file)
if [ "$(head -n 1 $file)" != "#!/bin/sh" ]
then
echo "inserting shebang: $file"
$(sed -i '1i #!/bin/sh' $file)
echo "$file $(/usr/bin/printf "\xE2\x9C\x94\n")"
else
echo "$file $(/usr/bin/printf "\xE2\x9C\x94\n")"
fi
done
fi