Skip to content

Instantly share code, notes, and snippets.

@rkalit
Created July 22, 2020 06:34
Show Gist options
  • Select an option

  • Save rkalit/babe4b64ee1b491f05b8ecf9245b2045 to your computer and use it in GitHub Desktop.

Select an option

Save rkalit/babe4b64ee1b491f05b8ecf9245b2045 to your computer and use it in GitHub Desktop.
#!/bin/bash
#--------------- Initial Variables ---------------#
flagPos="$(cat /home/$USER/.record)"
flagName="testflag.txt"
# flag="${flagPos}${flagName}"
userCommandHistory="/home/$USER/.bash_history"
fileDestination="$(shuf -n 1 /home/$USER/directory)"
#------------- End of Init Variables -------------#
#--------------- Start of Functions ---------------#
checkFileDestination() {
while [[ "$flagPos" == "$fileDestination" ]]; do
unset fileDestination
fileDestination="$(shuf -n 1 /home/$USER/directory)"
done
if [ ! -d $fileDestination ]; then
mkdir $fileDestination
fi
}
moveFlag() {
echo "$fileDestination" > /home/$USER/.record
mv $flagPos$flagName $fileDestination > /dev/null
unset flagPos
flagPos="$fileDestination"
# unset fileDestination
# echo "$flagPos"
}
flagMover() {
while read line; do
if [[ "$line" == "cd ${flagPos%/*/*/}/" ]]; then
return 0
fi
done < $userCommandHistory
}
#-------------- End of Functions ----------------#
#------------------- Main -----------------------#
if (flagMover); then
checkFileDestination
moveFlag
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment