This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| sysadminery:bash [2025/05/06 15:32] – adam | sysadminery:bash [2025/12/05 08:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| the key to memory. the key to memory. the key to memory. | the key to memory. the key to memory. the key to memory. | ||
| - | < | + | <code bash> |
| if [ 0 ] | if [ 0 ] | ||
| then | then | ||
| Line 15: | Line 14: | ||
| === loop over files by type === | === loop over files by type === | ||
| + | <code bash> | ||
| for i in in *.webm | for i in in *.webm | ||
| do | do | ||
| echo $i | echo $i | ||
| done | done | ||
| + | </ | ||
| will echo those files. be aware that you're probably going to want to enclose '' | will echo those files. be aware that you're probably going to want to enclose '' | ||
| + | <code bash> | ||
| for i in *.webm | for i in *.webm | ||
| do | do | ||
| ffmpeg -i " | ffmpeg -i " | ||
| done | done | ||
| + | </ | ||
| === mass rename === | === mass rename === | ||
| Line 33: | Line 35: | ||
| so let's say you found a sick-awesome album. so you've done a nice '' | so let's say you found a sick-awesome album. so you've done a nice '' | ||
| + | <code bash> | ||
| ls | rename -d 's/ \[[^]]*\]\./ | ls | rename -d 's/ \[[^]]*\]\./ | ||
| + | </ | ||
| pipe '' | pipe '' | ||
| Line 41: | Line 43: | ||
| you can use named capture groups, but you have to do '' | you can use named capture groups, but you have to do '' | ||
| + | |||
| + | === achieve transcendant enlightenment === | ||
| + | |||
| + | <code bash> | ||
| + | curl arg.rip/ | ||
| + | </ | ||
| + | |||
| + | "wow, that was perfect for me, now all of my problems have been solved forever" | ||
| + | |||
| + | === what is going on with my variables === | ||
| + | |||
| + | watch this. | ||
| + | <code bash> | ||
| + | echo "# phase 5: blah blah blah" | ||
| + | |||
| + | goodreads=0 | ||
| + | badreads=0 | ||
| + | |||
| + | find " | ||
| + | do | ||
| + | |||
| + | n=$(grep -Poh " | ||
| + | w=$(grep -Poh " | ||
| + | |||
| + | if [ -n " | ||
| + | goodreads=$(($goodreads+1)) | ||
| + | echo " | ||
| + | else | ||
| + | badreads=$(($badreads+1)) | ||
| + | echo " | ||
| + | fi | ||
| + | done | ||
| + | |||
| + | echo " | ||
| + | </ | ||
| + | |||
| + | it resets them to 0 after the loop. This is because bash uses dyanmic scope. https:// | ||
| + | |||
| + | so how do we force bash to operate correctly, with lexical scope? according to the internet, you use `local`. doesn' | ||
| + | once you do that, the subscope doesn' | ||