2
\$\begingroup\$

This code checks to make sure a directory is hidden and if not hides it. Then if hidden it will prompt for password and if password matches it will un-hide it. There is also an argument to open un-hidden directory too.

#! /bin/bash
DIR="path/untitled"
DIR2="path/.untitled"
password="Z2FsdGVkX18vy4f4QRB3qnb5vIWR0x+tlZmdAmPxX8Y="
input=""
result=""
basic()
{
 if [ -d "$DIR" ]
 then
 clear
 mv $DIR $DIR2
 elif [ -d "$DIR2" ]
 then
 echo -n ": "
 read -s input
 result=$(echo "$password"| openssl enc -aes-128-cbc -a -d -salt -pass pass:wtf)
 if [ "$result" = "$input" ]
 then
 clear
 mv $DIR2 $DIR
 else
 clear
 fi
 else
 :
 fi
exit
}
opendir()
{
 if [ -d "$DIR" ]
 then
 clear
 mv $DIR $DIR2
 elif [ -d "$DIR2" ]
 then
 echo -n ": "
 read -s input
 result=$(echo "$password"| openssl enc -aes-128-cbc -a -d -salt -pass pass:wtf)
 if [ "$result" = "$input" ]
 then
 clear
 mv $DIR2 $DIR
 open $DIR
 else
 clear
 fi
 else
 :
 fi
exit
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Main ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if [ $# -eq 0 ]
then
 basic
elif [ $# -eq 1 ]
then
 if [ "1ドル" = "-o" ]
 then
 opendir
 else
 :
 fi 
fi
clear
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ End of File ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rolfl
98.1k17 gold badges219 silver badges419 bronze badges
asked Sep 1, 2015 at 1:50
\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

Avoid echo -n

Avoid using any flags of echo, like this, as it's not portable:

 echo -n ": "

This is more portable, and produces the same output:

 printf ": "

Get rid of empty statements

These empty else statements are pointless, I suggest to remove them:

else
 :

Simplify

This can be simplified:

 if [ "$result" = "$input" ]
 then
 clear
 mv $DIR2 $DIR
 else
 clear
 fi

Since in both branches of the if-else you clear, this is the same:

 clear
 if [ "$result" = "$input" ]
 then
 mv $DIR2 $DIR
 fi

Quote variables in paths

Typically you should double-quote variables, especially when used as paths. So instead of this:

 mv $DIR2 $DIR

This is recommended and safer:

 mv "$DIR2" "$DIR"

Avoid duplicated code

The code in opendir and basic is almost the same. The only difference I see is the content of the "$result" = "$input" conditions. Consider using a single function with a flag to determine the behavior inside the main conditional.

answered Sep 2, 2015 at 0:46
\$\endgroup\$
1
  • \$\begingroup\$ Thank you for the suggestion. I updated my code to reflect them. When you get time please take a look at the new code. \$\endgroup\$ Commented Sep 2, 2015 at 15:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.