I have never done shell scripting before and need some help with a small project.
I want a user to enter three file names and check that the user has input THREE names and give an error if its more or less. The files will be sorted into another file but that is working fine just having problem with checking what the user has entered.
I have tried
echo Please select the three files you want to use
read $file1 $file2 $file3
if ! [ $# -eq 3 ]; then
echo "Please enter THREE values"
fi
Without changing your
readcommand:if [ -z "$file1" -o -z "$file2" -o -z "$file3" ]; then echo "Please enter THREE values" fiBut the preferred way is using arrays here:
read -a files if [ ! ${#files[@]} -eq 3 ]; then echo "Please enter THREE values" fiAnd btw. the elements are
${files[0]},${files[1]}and${files[2]}or, you could loop the array:for f in "${files[@]}"; do echo $f done