Created
July 22, 2020 06:34
-
-
Save rkalit/babe4b64ee1b491f05b8ecf9245b2045 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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