Klar med första scriptet till Övning 3, labb 4 samt skapat stubb till script 2

This commit is contained in:
2013-12-12 20:30:13 +01:00
parent 6164767b87
commit ee25830ebf
4 changed files with 45 additions and 30 deletions

36
Labb4/ovning3_script1.sh Executable file
View File

@@ -0,0 +1,36 @@
#!/bin/bash
# Jack-Benny Persson
# LX13
# Övning 3, version1, labb 4
# Replace words
# Define some variables
File="$1"
Old="$2"
New="$3"
# Sanity checks
if [ $# -ne 3 ]; then
if [ $# -eq 1 ]; then # If there is just one arg and
if [ -r $# ]; then # if the file exists,
cat $1 # just print it
fi
else
echo "Usage $0 <filename> <old_word> <new_word>"
exit 2 # If it dosen't, exit and print usage
fi
fi
if [ ! -r $File ]; then # If there is no such file
echo "We can't read that file"
exit 2
fi
# Main script
Data=`cat $1` # Put the content of the file in Data
Alt=${Data/$Old/$New} # Replace the word (kinda lika sed 's/old/new/')
echo "$Alt" # Print the content with the replaced words
exit 0