Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shellcheck reports a few issues #26

Open
MakisH opened this issue Jun 27, 2021 · 0 comments
Open

Shellcheck reports a few issues #26

MakisH opened this issue Jun 27, 2021 · 0 comments

Comments

@MakisH
Copy link

MakisH commented Jun 27, 2021

shellcheck is a great and very easy to use tool to find out potential issues with shell scripts. When checking flash-it, it reports a few easy to fix issues:

 shellcheck flash-it.sh 

In flash-it.sh line 86:
    command -v $dependency >/dev/null 2>&1 || {
               ^---------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
    command -v "$dependency" >/dev/null 2>&1 || {


In flash-it.sh line 95:
    check_dependency $dependency
                     ^---------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
    check_dependency "$dependency"


In flash-it.sh line 195:
read -p "Device node (/dev/sdX): " DEVICE_NODE
^--^ SC2162: read without -r will mangle backslashes.


In flash-it.sh line 201:
if [ $DEVICE_NODE == "raw" ]; then
     ^----------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
if [ "$DEVICE_NODE" == "raw" ]; then


In flash-it.sh line 208:
for PARTITION in $(ls ${DEVICE_NODE}*)
                 ^-------------------^ SC2045: Iterating over ls output is fragile. Use globs.


In flash-it.sh line 211:
    sudo umount $PARTITION
                ^--------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
    sudo umount "$PARTITION"


In flash-it.sh line 221:
	LOOP_NODE=`ls /dev/loop?p1 | cut -c10-10`
                  ^-----------------------------^ SC2006: Use $(...) notation instead of legacy backticked `...`.
                   ^-------------^ SC2012: Use find instead of ls to better handle non-alphanumeric filenames.

Did you mean: 
	LOOP_NODE=$(ls /dev/loop?p1 | cut -c10-10)


In flash-it.sh line 226:
if [ $(echo $DEVICE_NODE | grep mmcblk || echo $DEVICE_NODE | grep loop) ]; then
     ^-- SC2046: Quote this to prevent word splitting.
            ^----------^ SC2086: Double quote to prevent globbing and word splitting.
                                               ^----------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
if [ $(echo "$DEVICE_NODE" | grep mmcblk || echo "$DEVICE_NODE" | grep loop) ]; then


In flash-it.sh line 234:
sudo mkfs.ext4 -F -L boot $BOOTPART # 1st partition = boot
                          ^-------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
sudo mkfs.ext4 -F -L boot "$BOOTPART" # 1st partition = boot


In flash-it.sh line 235:
sudo mkfs.ext4 -F -L data $DATAPART # 2nd partition = data
                          ^-------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
sudo mkfs.ext4 -F -L data "$DATAPART" # 2nd partition = data


In flash-it.sh line 254:
    TEMP=`ls $ROOTFS_DIR/*/*.tar.bz2`
         ^--------------------------^ SC2006: Use $(...) notation instead of legacy backticked `...`.

Did you mean: 
    TEMP=$(ls $ROOTFS_DIR/*/*.tar.bz2)


In flash-it.sh line 257:
sudo mount $DATAPART "$MOUNT_DATA" # Mount data partition
           ^-------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
sudo mount "$DATAPART" "$MOUNT_DATA" # Mount data partition


In flash-it.sh line 264:
sudo mount $BOOTPART "$MOUNT_BOOT" # Mount boot partition
           ^-------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
sudo mount "$BOOTPART" "$MOUNT_BOOT" # Mount boot partition


In flash-it.sh line 268:
echo `ls $MOUNT_BOOT`
     ^--------------^ SC2046: Quote this to prevent word splitting.
     ^--------------^ SC2005: Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.
     ^--------------^ SC2006: Use $(...) notation instead of legacy backticked `...`.

Did you mean: 
echo $(ls $MOUNT_BOOT)


In flash-it.sh line 278:
for PARTITION in $(ls ${DEVICE_NODE}*)
                 ^-------------------^ SC2045: Iterating over ls output is fragile. Use globs.
                      ^------------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
for PARTITION in $(ls "${DEVICE_NODE}"*)


In flash-it.sh line 281:
    sudo umount $PARTITION
                ^--------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
    sudo umount "$PARTITION"

For more information:
  https://www.shellcheck.net/wiki/SC2045 -- Iterating over ls output is fragi...
  https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt...
  https://www.shellcheck.net/wiki/SC2012 -- Use find instead of ls to better ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant