#n.sh
#by D@CC
#on 2024BFeb09
#status: tested, no major issues
# source:https://linuxhandbook.com/if-else-bash/
# cd to the folder containing the package
#sample invocation:  sh n.sh IX_textpack_pkg.py
#    or              sh n.sh IX_testpack_pkg.py any_pkg.py
# (note @ means a list of one or all parms incl the cntr)
# https://www.howtogeek.com/439199/15-special-characters-you-need-to-know-for-bash/
# should execute:
# python /home/pi/Desktop/a/sandBox/nShowDefs.py <IX_textpack_pkg.py
#ctrl="-d"    # use -d if no ctrl is defined
#**************************************************
# next 2 statements do not work in bookworm OS BASH
#s1= "${$file:0:1}"
#s1 = $file | cut -c1-1
# *************************************************
list=$@
echo "CLI: $list:"
ctrl="-x"
#echo "22 ctrl:$ctrl"
for file in $list
 do
  #$isToProcess = "True"
  echo "*****************file is :$file"
  # is first char of $file = "-" "
  cntFiles=$cntFiles+1     #suffix the char "1"
  #echo "cntFiles:$cntFiles"
  #echo "30 before if cntFiles ctrl:$ctrl"
  if [ $cntFiles = "+1" ] ; then
    #echo "first time through"
    # so process the ctrl string
    #echo "s1:$s1"
    #echo "35 ctrl:$ctrl"
    #ctrl="-x"
    #echo "37 ctrl:$ctrl"
    if [ '$ctrl' != '-x' ]; then
      #echo "new ctrl already set"
      doh=""  # same as Python "pass"
    fi
    if [ $file = '-a' ] ; then    ctrl="$file" ;fi
    if [ $file = '-all' ]; then    ctrl="$file" ;fi
    if [ $file = '-c' ] ; then    ctrl="$file" ;fi
    if [ $file = '-d' ] ; then    ctrl="$file" ;fi
    if [ $file = '-dm' ] ; then    ctrl="$file" ;fi
    if [ $file = '-g' ] ; then    ctrl="$file" ;fi
    if [ $file = '-h' ] ; then    ctrl="$file" ;fi
    if [ $file = '-i' ] ; then    ctrl="$file" ;fi
    if [ $file = '-m' ] ; then    ctrl="$file" ;fi
    if [ $file = '-md' ] ; then    ctrl="$file" ;fi
    if [ $file = '-o' ] ; then    ctrl="$file" ;fi
    if [ $file = '-s' ] ; then    ctrl="$file" ;fi
    if [ $file = '-u' ] ; then    ctrl="$file" ;fi
    if [ $file = '-_' ] ; then    ctrl="$file" ;fi
    #fi
    #echo "57 setting ctrl to non-x" 
    #fi
    if [ '$ctrl' = '-x' ] ; then
     echo "60 ctrl:$ctrl"
    fi
    if [ $ctrl != '-x' ]; then
     #echo "new ctrl:$ctrl"
     #echo "skipping $ctrl control (Its not a file)"
     # do not try to process the ctrl eg -a
     #isToProcess="False"
     #echo "67 before continue ctrl:$ctrl"
     continue   # exit from the do
    fi
  fi
  #  Now process the non-first files
  echo "processing file named: $ctrl $file"
  #if [ $isToProcess ="True" ] ; then
  python /home/pi/Desktop/a/sandBox/n_v05.py $ctrl <$file
  #fi
 done
echo "all done"
#n.sh should display
#list of modules in this package
#/n.sh
