-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappend
More file actions
executable file
·36 lines (30 loc) · 1.05 KB
/
Copy pathappend
File metadata and controls
executable file
·36 lines (30 loc) · 1.05 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
#!/usr/bin/env sh
#
# Script name: append
# Description: A bash script for appending a line text to a file
# Dependencies: coreutils
# GitHub: https://www.github.com/pchstpch/myminiutils
# License: https://www.github.com/pchstpch/LICENSE
# Contributers: Derek Taylor, Muneeb Mennad
#
# Set w/ the flags "-e", "-u", "-o pipefail" cause the script to
# fail if certain things happen, which is a good thing. Otherwise
# we can get hidden bugs that are hard to discover.
set -euo pipefail
# Check if a filename argument is provided
if [ "$#" -ne 1 ]; then
echo "Usage: append <filename>"
exit
fi
blue="$(tput setaf 4 bold)"
green="$(tput setaf 2 bold)"
reset="$(tput sgr0)"
filename="$1"
# 'read -e' gets user input with readline support
# -p sets the prompt
# -r prevents backslash escapes from being interpreted
echo "Enter text to append to file ${blue}$filename${reset}:"
read -e -r -p "${blue}>>>${reset} " input_text
# Append the entered text followed by a newline to the file
echo "$input_text" >> "$filename"
echo "${green}✓${reset} Text successfully appended!"