albibacsi

bash arrays, var substituions, etc

Apr 17th, 2018 (edited)
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. http://wiki.bash-hackers.org/syntax/pe
  2. https://www.tldp.org/LDP/abs/html/parameter-substitution.html
  3.  
  4. The simplest way to copy a non-associative array in bash is to:
  5. arrayClone=("${oldArray[@]}")
  6.  
  7.  
  8. AAA=( $(git branch -a) )
  9. AAA=( "${AAA[@]//remotes\/origin\/}" )
  10.  
  11. # split string on spaces, result is an array
  12. p=( ${package_file//-/ } )
  13.  
  14.  
  15. shopt -s extglob
  16. A=aaaaXXaaa; echo "${A//+([^A-Z])/=}"
  17. =XX=
  18.  
  19. A=aaaaXXaaa; echo "${A//+([A-Z])/=}"
  20. aaaa=aaa
  21.  
  22. A=aaaa//aaa; echo "${A//+(\/)/=}"
  23. aaaa=aaa
  24.  
  25. **************************************************
  26.  
  27. CMD=( python3 somescript.py -r -d "$DAYS" )
  28.  
  29. if test -n "${EXTRA_PARAMS-}"; then
  30. IFS=" " read -r -a arr <<< "$EXTRA_PARAMS"
  31. CMD+=( "${arr[@]}" );
  32. fi
  33.  
  34. # executing python script
  35. "${CMD[@]}"
  36. **************************************************
  37.  
  38.  
  39.  
Add Comment
Please, Sign In to add comment