Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Using Files As Databases

View addb.sh
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
#!/bin/sh
# Access AddressBook file and use it as a database
 
# Variables
name=$1
number=$2
db=AddressBook
 
### AddressBook File Example ###
# Maria Daher (27)5564-4392 #
# Nathan Campos (27)3325-9732 #
# Thiago B. (32)5302-4892 #
# Lucas Pinher (23)0982-2389 #
# Eduardo V. (75)9234-8234 #
################################
 
# Listing what's on the file
cat $db
 
# Searching inside the file for the term inputted as the first argument
grep "$name" $db
 
# Adding someone on the file
echo "$name $number" >> $db # Add a new input on the file
sort -o $db $db # Organize the db/file content
 
# Deleting records from the file
grep -v "$name" $db > /tmp/$$ # Create the new file without the choosen record on /tmp/(PID)
mv /tmp/$$ $db # Overwrite the file with the one without the record removed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.