Use a ( subshell ) to avoid having to cd back. Open
cd ..
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Use a ( subshell ) to avoid having to cd back.
Problematic code:
for dir in */
do
cd "$dir"
convert index.png index.jpg
cd ..
done
Correct code:
for dir in */
do
(
cd "$dir" || exit
convert index.png index.jpg
)
done
or
for dir in */
do
cd "$dir" || exit
convert index.png index.jpg
cd ..
done
Rationale:
When doing cd dir; somestuff; cd ..
, cd dir
can fail when permissions are lacking, if the dir was deleted, or if dir
is actually a file.
In this case, somestuff
will run in the wrong directory and cd ..
will take you to an even more wrong directory. In a loop, this will likely cause the next cd
to fail as well, propagating this error and running these commands far away from the intended directories.
Check cd
s exit status and/or use subshells to limit the effects of cd
.
Exceptions
If you set variables you can't use a subshell. In that case, you should definitely check the exit status of cd
, which will also silence this suggestion.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
The = here is literal. To assign by index, use ( [index]=value ) with no spaces. To keep as literal, quote it. Open
-Dmaven.plugin.validation=NONE
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
The = here is literal. To assign by index, use ( [index]=value ) with no spaces. To keep as literal, quote it.
Problematic code:
array=( [index] = value )
Correct code:
array=( [index]=value )
Rationale:
The shell doesn't care about the =
sign in your array assignment because it's not part of a recognized index assignment. Instead, it's considered a literal character and becomes part of an array element's value.
In the example problematic code, this is because the =
was intended to set the index, but the shell will not recognize it when it is surrounded by spaces.
Make sure to remove any spaces around the =
when assigning by index, such as in the correct code.
If you wanted the =
to be a literal part of the array element, add quotes around it, such as env=( "LC_CTYPE=C" )
or specialChars=( "=" "%" ";" )
.
Exceptions:
None.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Can't follow non-constant source. Use a directive to specify location. Open
source "$BASH_BUDDY_ROOT/lib/java_utils.sh"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Can't follow non-constant source. Use a directive to specify location.
Problematic code:
. "$(find_install_dir)/lib.sh"
Correct code:
# shellcheck source=src/lib.sh
. "$(find_install_dir)/lib.sh"
Rationale:
ShellCheck is not able to include sourced files from paths that are determined at runtime. The file will not be read, potentially resulting in warnings about unassigned variables and similar.
Use a [[Directive]] to point shellcheck to a fixed location it can read instead.
Exceptions:
If you don't care that ShellCheck is unable to account for the file, specify # shellcheck source=/dev/null
.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Can't follow non-constant source. Use a directive to specify location. Open
source "$BASH_BUDDY_ROOT/lib/maven_utils.sh"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Can't follow non-constant source. Use a directive to specify location.
Problematic code:
. "$(find_install_dir)/lib.sh"
Correct code:
# shellcheck source=src/lib.sh
. "$(find_install_dir)/lib.sh"
Rationale:
ShellCheck is not able to include sourced files from paths that are determined at runtime. The file will not be read, potentially resulting in warnings about unassigned variables and similar.
Use a [[Directive]] to point shellcheck to a fixed location it can read instead.
Exceptions:
If you don't care that ShellCheck is unable to account for the file, specify # shellcheck source=/dev/null
.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Can't follow non-constant source. Use a directive to specify location. Open
source "$BASH_BUDDY_ROOT/lib/trap_error_info.sh"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Can't follow non-constant source. Use a directive to specify location.
Problematic code:
. "$(find_install_dir)/lib.sh"
Correct code:
# shellcheck source=src/lib.sh
. "$(find_install_dir)/lib.sh"
Rationale:
ShellCheck is not able to include sourced files from paths that are determined at runtime. The file will not be read, potentially resulting in warnings about unassigned variables and similar.
Use a [[Directive]] to point shellcheck to a fixed location it can read instead.
Exceptions:
If you don't care that ShellCheck is unable to account for the file, specify # shellcheck source=/dev/null
.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Can't follow non-constant source. Use a directive to specify location. Open
source "$BASH_BUDDY_ROOT/lib/common_utils.sh"
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Can't follow non-constant source. Use a directive to specify location.
Problematic code:
. "$(find_install_dir)/lib.sh"
Correct code:
# shellcheck source=src/lib.sh
. "$(find_install_dir)/lib.sh"
Rationale:
ShellCheck is not able to include sourced files from paths that are determined at runtime. The file will not be read, potentially resulting in warnings about unassigned variables and similar.
Use a [[Directive]] to point shellcheck to a fixed location it can read instead.
Exceptions:
If you don't care that ShellCheck is unable to account for the file, specify # shellcheck source=/dev/null
.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Expected an indentation at 8 instead of at 6. Open
cd "$JAVA8_HOME/.."/8.0.345*
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 8 instead of at 6. Open
cd "$d" || cu::die "Fail to cd java home of v8.0.345($d)!"
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
# Maven Plugin Validation
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
export JAVA8_0_345_HOME
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
# https://maven.apache.org/guides/plugins/validation/index.html
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
"$JAVA8_0_345_HOME"
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
jvu::switch_to_jdk "$jdk"
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
cu::head_line_echo "test with Java: $JAVA_HOME"
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 8 instead of at 6. Open
d="$(ls -v -d "$JAVA8_HOME/../.."/8.* | tail -n 1)" || cu::die "Fail to get latest java 8 home!"
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
-DperformRelease -P'!gen-sign' -Pgen-code-cov
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
-Dmaven.plugin.validation=NONE
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
# just test without build
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
mvu::mvn_cmd "${SUREFIRE_TEST_GOAL[@]}"
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 8 instead of at 6. Open
cd "$d" || cu::die "Fail to cd java8 home"
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
"${MVU_DEFAULT_MVN_OPTS[@]}"
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
# already tested by above `mvn install`
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
# shellcheck disable=SC2086
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
${CI_MORE_MVN_OPTS:+${CI_MORE_MVN_OPTS}}
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 8 instead of at 6. Open
# shellcheck disable=SC2012
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
"$default_build_jdk_version"
- Create a ticketCreate a ticket
- Exclude checks
Expected an indentation at 4 instead of at 2. Open
[ "$jdk" = "$default_build_jdk_version" ] && continue
- Create a ticketCreate a ticket
- Exclude checks