Advertisement
genBTC

bash scripting STDIN over | pipe, vs. Argument $1 confusion

Jul 2nd, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. #Problem. STDIN over | pipe, vs. Argument $1 confusion
  2.  
  3. #This works (for one argument):
  4. bash$: dofunction2 'RaidZ-2TBx3/1'
  5.  
  6. #This does not (for multiple lines):
  7. bash$: getfunction1 | dofunction2
  8.  
  9. #Works:
  10.  
  11. diffsnapshotadjacentpairsA() {
  12. getsnapshotadjacentpairs $1 | zfsdiffawksnapshot
  13. }
  14.  
  15. #first export(including subfunctions):
  16. export -f diffsnapshotadjacentpairsA zfsdiffawksnapshot getsnapshotadjacentpairs getzfssnapshots
  17. #Argument:
  18. diffsnapshotadjacentpairsA 'RaidZ-2TBx3/1'
  19. #STDIN:
  20. getzfsdatasets | grep 'RaidZ-2TBx3/1' | xargs -I {} bash -c 'diffsnapshotadjacentpairsA "$1"' _ {}
  21.  
  22. #Works:
  23.  
  24. diffsnapshotadjacentpairsB() {
  25. if (($#)); then
  26. getsnapshotadjacentpairs $1 | zfsdiffawksnapshot
  27. else while read -r; do
  28. getsnapshotadjacentpairs $REPLY | zfsdiffawksnapshot
  29. done; fi
  30. }
  31.  
  32. #Argument:
  33. diffsnapshotadjacentpairsB 'RaidZ-2TBx3/1'
  34. #STDIN:
  35. getzfsdatasets | grep 'RaidZ-2TBx3/1' | diffsnapshotadjacentpairsB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement