RolandsKenins

Handling Args In Shell

Jun 17th, 2018
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.68 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. for I in $@                     # FYI: $@ - the first argument !$# - the last argument $# - number of arguments
  4. do
  5.    # TODO: Do something with arguments like..
  6.    echo $I
  7. done
  8.  
  9. # Example for handling unicode string arguments by storing them into array elements
  10. K=1                             # IMPORTANT! This is our index for elements in array
  11. for I in $@
  12. do
  13.    ARRAY[$K]=$I
  14.    # TODO: Whatever you want
  15.    echo ${ARRAY[$K]}
  16.    K=$(( K + 1 ))               # Next element in array
  17. done
  18.  
  19. # To operate with file parsed as argument and read it line by line
  20. source $1
  21. while read line
  22. do
  23.    # TODO: Something whatever should be done with this file
  24. done < $1
  25.  
  26. exit 0
Add Comment
Please, Sign In to add comment