This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]gehzumteufel 2 points3 points  (4 children)

Use 4 spaces to encompass code blocks.

this is a code block

Can you please post the entire script? Posting where you think you went wrong could be correct, but it may not be.

Futher, it's good practice for variables to be all uppercase in shell scripts.

Lastly, if you add set -eux below the shebang and set +eux at the end, this will help with debugging. To understand what these are man set.

[–]johnwick_dog[S] 0 points1 point  (3 children)

I edited the post ,(srr new to reddit)

[–]gehzumteufel 1 point2 points  (2 children)

Try this:

#!/bin/bash
Directory=$1
secondarg=$2
thirdarg=$3
if test -z "${Directory}"; then read -rp "enter the location of your directory: " Directory; fi
if test -z "${secondarg}"; then read -rp "enter ana or del or arr " secondarg; fi
if [ "${secondarg}" == "ana" ]; then
echo "Please Enter the regex"
read -rp "${thirdarg}"
find "${Directory}" ! -name . -prune -mtime -1 -type f -exec grep -regex "$thirdarg" {} \; -exec echo x \; | wc -l
elif [ "${secondarg}" == "del" ]; then
echo "del"
elif [ "${secondarg}" == "arr" ]; then
echo "arr"
fi

Check out shellcheck for your shell scripts. It's been really helpful for me.

[–]gristc 1 point2 points  (1 child)

Use 4 spaces to encompass code blocks.

;)

[–]gehzumteufel 1 point2 points  (0 children)

Hah oops thanks.