Created
July 19, 2024 03:16
-
-
Save isurfer21/421b5ca7b7116cfd31e7f3e7faba0211 to your computer and use it in GitHub Desktop.
Revisions
-
isurfer21 created this gist
Jul 19, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ #!/bin/bash HELP_MENU="Usage: ${0##*/} [-h|--help] <rust_filename> Compile and run a Rust file, then delete the binary. Options: -h, --help Show this help menu " if [ $# -eq 0 ]; then echo "Error: Rust filename is required" echo "$HELP_MENU" exit 1 fi while [ $# -gt 0 ]; do case "$1" in -h|--help) echo "$HELP_MENU" exit 0 ;; *) RUST_FILENAME="$1" ;; esac shift done if [ ! -f "$RUST_FILENAME" ]; then echo "Error: File '$RUST_FILENAME' does not exist" exit 1 fi rustc "$RUST_FILENAME" if [ $? -ne 0 ]; then echo "Error: Compilation failed" exit 1 fi BIN_FILENAME="${RUST_FILENAME%.rs}" ./"$BIN_FILENAME" rm "$BIN_FILENAME"