439
submitted 1 year ago* (last edited 1 year ago) by joyjoy@lemmy.world to c/programmer_humor@programming.dev
you are viewing a single comment's thread
view the rest of the comments
[-] joyjoy@lemmy.world 2 points 1 year ago* (last edited 1 year ago)

Is your issue about just syntax?

for part in $text; do
  echo "xX${part}Xx"
done

In bash, this loops over each word in a variable. If you want each line, you'll need to use a while read loop instead.

while read -r line; do
  echo "xX${line}Xx"
done <<< "$text"
[-] ArcaneSlime@lemmy.dbzer0.com 2 points 1 year ago

I think my issue may be more than just syntax, I really am inexperienced lol, all just learning as I go (unix philosophy and all lol, I kid).

The for loop I stole from the internet for use with ffmpeg is

for i in *$input; do ffmpeg -i "$i" "${i%.*}$output"; done

So I know what it does, it takes the input (read by the script earlier) filetype and changes it to the output filetype also read earlier for all of the files of $input type in the current directory, and I know how I got input and output as variables, and I know the ffmpeg -i foo -o bar command, but I get completely lost on "$i" "${i%.*}$output";. I don't really understand when to use what brackets or where I need semicolons and why, though I do understand that $ calls a variable and * is an operator to designate "all," I'm not entirely sure what this part of my script is doing (as this loop is the part I copied from stackexchange, and only half understood it "but it worked so fuck it" lol.)

[-] joyjoy@lemmy.world 3 points 1 year ago

The ${} syntax manipulates a variable. In this instance, I believe % removes a suffix. # is for a prefix. I can never remember which is which.

Semicolons just separate statements. You can replace them with a new line to get the same effect.

[-] ArcaneSlime@lemmy.dbzer0.com 1 points 1 year ago

Thanks for the info, it definitely helped!

this post was submitted on 23 Jul 2023
439 points (94.7% liked)

Programmer Humor

19623 readers
1 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS