0
#! /bin/bash
# Script to add all scripts to the main one for dispersion to the right scripts
# Must be run in the sudo mode

if [-z $1] then                             # Set the dir to scan
    scpdir="/default-dir/";
elif
    scpdir=$1;
fi
slffil=$scpdir"thisbashfile.sh";                # Ignore this file
if [-z $2]    then                              # Set the target output file
    tgtfil=$scpdir"myoutfile";      # Ignore the target file
elif
    tgtfil=$2;
fi

for i in `ls $scpdir*.*`; do
    # Set iteration skips/continue for: '~', 'html', 'tar' $slffil, $tgtfil
    if [ "$i" == "$slffil" ]; then continue; fi
    if [ "$i" == "$tgtfil" ]; then continue; fi
    case "$i" in [*~] | [*.tar.*] | [*.html] | [*.list] | [*.deb] | [*DRBL])
        continue;;
    esac;
    echo "$i";
done

I need a 3rd "IF" line for the ~, html, tar files in this directory. Should I use a regex for this or is there another simple way to eliminate these files from my dir scan?

OldManRiver
  • 128
  • 1
  • 6
  • 4
    Please take a look: http://www.shellcheck.net/ – Cyrus Feb 15 '19 at 18:40
  • Also see [ParsingLs](http://mywiki.wooledge.org/ParsingLs), and note that `eq` is not a valid test operator. (`-eq` is, but that's only for numeric comparisons). And you're comparing `$1`, not `$i`. And if you want to be doing pattern matches, `case` is the right tool for the job anyhow. – Charles Duffy Feb 15 '19 at 18:43
  • 1
    `for i in "$srcdir"/*; do case $i in *~|*.tar|*.html) continue;; *) echo "$i";; esac; done` -- see https://wiki.bash-hackers.org/syntax/ccmd/case. And really, *do* run all your code through shellcheck; my notes are just supplemental. – Charles Duffy Feb 15 '19 at 18:45
  • Charles, Based on your comment I changed my for loop and it is not passing the shellcheck and also erroring locally – OldManRiver Feb 16 '19 at 00:01
  • Charles, Changed the "CASE" so it's not erroring, but not actually working as in skipping over the defined file ext or files containing the strings. – OldManRiver Feb 16 '19 at 00:21
  • Square brackets are wrong in the `case` statement. `[aeiou]` matches *exactly one* character (a vowel, any vowel). Similarly, `[*.list]` matches the character `*`, the character `l`, the character `i`, etc. – Charles Duffy Feb 16 '19 at 21:12
  • Anyhow, there are still a whole bunch of bugs in here that shellcheck will flag. Fix those *and the issues discussed in answers to the questions linked as duplicates*, comment @-noticing me when you've done so, and I'll reopen the question if it's eligible at that time. – Charles Duffy Feb 16 '19 at 21:14
  • Note that you need to comment `@CharlesDuffy`, not just `Charles`, for me to necessarily see it; I wouldn't have noticed your prior comments if I weren't looking back over the last several days' comment threads, which is not something I typically do. – Charles Duffy Feb 16 '19 at 21:15
  • Charles, thanks for the "{}" input! Was just following a HOWTO, which showed them, but now know, not necessay! – OldManRiver Feb 18 '19 at 22:08

0 Answers0