-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_new_script
More file actions
executable file
·64 lines (49 loc) · 1.02 KB
/
my_new_script
File metadata and controls
executable file
·64 lines (49 loc) · 1.02 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
58
59
60
61
62
63
64
#!/bin/bash
# Builds Bash Scripting files
# Alias => newscript
# Help message
if [[ $1 = "-h" ]] || [[ $1 = "--help" ]]
then
echo "
$(basename "$0") [-h] (name)
-- script to build template for other scripts
where:
-h (--help) show help text
"
exit 0;
fi
# Check if user gave a name, if not, prompt them to
if [[ -z $1 ]]
then
read -p "Please give a name for your new script:
" name
else
name="$1"
fi
# Path for the file
script_path="${HOME}/Desktop/scripts/${name}"
# Make the file for the new script
touch "$name"
# Change the permissions so the file is executable
chmod u+x "$name"
# Strings variables
flag="\$1"
base="\$(basename \"\$0\")"
# Build the template
echo "#!/bin/bash
# $name
# Help message
if [[ $flag = "-h" ]] || [[ $flag = "--help" ]]
then
echo \"
$base [-h] (name)
-- script to <add content here>
where:
-h (--help) show help text
exit 0;\"
fi
" >> $name
# Move file to scripts directory
mv $name $script_path
# Give user output
echo "Created script template '${name}' at ${script_path}"