"Fossies" - the Fresh Open Source Software Archive

Member "argbash-2.10.0/resources/examples/simple.sh" (22 Sep 2020, 1522 Bytes) of package /linux/privat/argbash-2.10.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "simple.sh": 2.9.0_vs_2.10.0.

    1 #!/bin/bash
    2 
    3 # DEFINE_SCRIPT_DIR([])
    4 # INCLUDE_PARSING_CODE([simple-parsing.sh])
    5 # ARGBASH_GO()
    6 # needed because of Argbash --> m4_ignore([
    7 ### START OF CODE GENERATED BY Argbash v2.10.0 one line above ###
    8 # Argbash is a bash code generator used to get arguments parsing right.
    9 # Argbash is FREE SOFTWARE, see https://argbash.io for more info
   10 
   11 # OTHER STUFF GENERATED BY Argbash
   12 script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || { echo "Couldn't determine the script's running directory, which probably matters, bailing out" >&2; exit 2; }
   13 . "$script_dir/simple-parsing.sh"  # '.' means 'source'
   14 
   15 
   16 ### END OF CODE GENERATED BY Argbash (sortof) ### ])
   17 # [ <-- needed because of Argbash
   18 
   19 
   20 # Now we take the parsed data and assign them no nice-looking variable names,
   21 # sometimes after a basic validation
   22 verbose=$_arg_verbose
   23 unit=$_arg_unit
   24 
   25 test -f $_arg_filename || { echo "Filename $_arg_filename doesn't seem to belong to a file"; exit 1; }
   26 filename="$_arg_filename"
   27 
   28 if [ $verbose = on ]
   29 then
   30   _b="bytes (B)"
   31   _kb="kibibytes (kiB)"
   32   _mb="mebibytes (MiB)"
   33 else
   34   _b="B"
   35   _kb="kiB"
   36   _mb="MiB"
   37 fi
   38 
   39 size_bytes=$(wc -c "$filename" | cut -f 1 -d ' ')
   40 
   41 test "$unit" = b && echo $size_bytes $_b && exit 0
   42 
   43 size_kibibytes=$(($size_bytes / 1024))
   44 test "$unit" = k && echo $size_kibibytes $_kb && exit 0
   45 
   46 size_mebibytes=$(($size_kibibytes / 1024))
   47 test "$unit" = M && echo $size_mebibytes $_mb && exit 0
   48 
   49 test "$verbose" = on && echo "The unit '$unit' is not supported"
   50 exit 1
   51 
   52 # ] <-- needed because of Argbash