I am writing a script that prompts for user inputs and then runs a find command.
What I have works, but it feels like I have a lot of duplicated code due to the if / else structure. Is it possible to have inline if
statement?
So, instead of this kind of thing:
if [[ $depth_boolean == y ]] || [[ $depth_boolean == yes ]]
then
if [[ $symlink_boolean == y ]] || [[ $symlink_boolean == yes ]]
then
find -L $location -maxdepth $depth -readable -iname "$query" -$find_type $find_type_option -$find_action
else
find $location -maxdepth $depth -readable -iname "$query" -$find_type $find_type_option -$find_action
fi
else
if [[ $symlink_boolean == y ]] || [[ $symlink_boolean == yes ]]
then
find -L $location -readable -iname "$query" -$find_type $find_type_option -$find_action
else
find $location -readable -iname "$query" -$find_type $find_type_option -$find_action
fi
fi
Is it possible to do something like this?
find if [ $symlink_boolean == y ]; then echo "-L";
fi $location if [ $symlink_boolean == y ]; then
echo "-maxdepth $depth"; fi -readable -iname "$query"
-$find_type $find_type_option -$find_action
The above doesn't work, but wondering if it is possible?