Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions hello-ocr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script lacks set -euo pipefail, which is a best practice for bash scripts. Without it, the script will continue executing even if a command fails or an unset variable is referenced, which can lead to silent errors and unpredictable behavior.

  • -e: Exit immediately if a command exits with non-zero status.
  • -u: Treat unset variables as an error.
  • -o pipefail: Return the exit status of the last command in a pipeline that failed.

Suggestion:

Suggested change
#!/bin/bash
#!/bin/bash
set -euo pipefail

greet() {
name=$1
echo Hello $name
}
greet $USER
Comment on lines +4 to +6

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable expansions $name and $USER are not quoted. Unquoted variables are subject to word splitting and glob expansion by the shell. For example, if $name contained spaces or special characters, the output would be incorrect or cause unexpected behavior. Always quote variable expansions to handle values with spaces or special characters safely.

Suggestion:

Suggested change
echo Hello $name
}
greet $USER
echo "Hello $name"
}
greet "$USER"

Loading