Shellcheck reports a few issues #26

Open
opened 2021-06-27 15:24:43 +00:00 by MakisH · 0 comments
MakisH commented 2021-06-27 15:24:43 +00:00 (Migrated from github.com)

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 ...
[shellcheck](https://github.com/koalaman/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 in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: crt0mega/flash-it#26
No description provided.