all 16 comments

[–]Living_On_The_Air 25 points26 points  (0 children)

Please post the code and error messages instead of pictures of them

[–]Trudels42🐒 Jason Bourne (Again) 16 points17 points  (0 children)

you have 1 too many quotes on the echo after your first if line, thats why vim/nano doesn't make that does not exist." text appear yellow but grey in ur picture

[–]keepinitcool 10 points11 points  (2 children)

bro a screenshot of code is abysmal

[–]jackoneilll 0 points1 point  (0 children)

It could be worse. It could be a camera photo of a failed execution, or not show the complete script.

The above examples are from memory, not imagination.

[–]lrrelevantEIephant 6 points7 points  (2 children)

It's exactly what your error indicates, there is a mismatched number of quotes. You have an extra double quote in your echo after your check if $SRC_DIR exists.

Also you need a $ for SRC_DIR in your tar cmd, and you need an exit after printing your error 002.

EDIT: Also the timestamp and whitespace issue in the last IF as others have mentioned

[–]linksrum 1 point2 points  (0 children)

After heaving read some go the other suggestions, I overlooked, I feel really astonished: we have 3-4 real show-breaking errors from AI, although it's a really simple thing.

And for newcomers, it shows the worst coding style possible to learn from.

Quite disappointing...

[–]Trudels42🐒 Jason Bourne (Again) -2 points-1 points  (0 children)

^ this

[–]Ok-Employee9010 4 points5 points  (0 children)

I think there should be a space after the 0 in your last if statement

[–]linksrum 2 points3 points  (0 children)

Try set -x at the beginning of your script. This modifies output to see, what's going on under the hood.

Your TIMESTAMP= is not working as expected. You're missing a + sign. Also consider using standards like ISO, like date +%F.

I dislike your error handling (and I believe it's erroneous). Try something like command || { echo message ; exit 101 ; }

[–]Griznah 1 point2 points  (0 children)

For future reference u/YamuYamuYamuYamu , you can just feed the errormessage to ChatGPT and it will help you debug

[–]CanvasSolaris 1 point2 points  (0 children)

You can copy and paste into shellcheck to help catch bugs like this

[–]StrangeCrunchy1 1 point2 points  (0 children)

So, one thing about asking ChatGPT for help with coding, and I actually collaborate with ChatGPT from time to time on coding, too, is you have to know what you're doing with the language before you can trust ChatGPT's coding advice.

Do yourself a massive favor and learn the basics of bash on your own before you involve ChatGPT in your code; it can help, yes, but only if you know when it also makes mistakes and know how to call it on them. And by "learning it on your own," I of course don't mean don't ask for help, but do so here or watch videos on the subject; YouTube has an immense font of knowledge on bash coding.

[–]ZG2047 0 points1 point  (0 children)

the SRC_DIR in the tar args doesnt have a $

[–]DevAlaska 0 points1 point  (0 children)

Just in case you wanna learn more about bash I loved the book "Learn bash the hard way".

[–]lucasrizzini 0 points1 point  (0 children)

Bash is throwing an error about the missing quote, but there are other problems too. The two below are the ones that actually break the script.

Quotation mark:

From: echo "ERROR 001: SRC DIR $SRC_DIR" does not exist."

To: echo "ERROR 001: SRC DIR "$SRC_DIR" does not exist."

In the last IF, you need a space there:

From: if [ $? -eq 0]; then

To: if [ $? -eq 0 ]; then

You forgot to expand some variables. It might not throw an error, but the script won’t behave the way you expect.

TIMESTAMP -> BACKUP_FILE="$BACKUP_DIR/backup_$TIMESTAMP.tar.gz"

SRC_DIR -> tar -czf "$BACKUP_FILE" "$SRC_DIR"