DEV Community

Discussion on: Bash Functions & Git - How to wipe out changes made to a specific file

Collapse
 
cookrdan profile image
Dan

I'm very new to bash myself, but I've been trying to make little scripts to make some things more efficient.

Bash has a few ways to do loops, including a for loop. Here's the basic thing of it as it applies to your script:

#!/bin/bash

func_name () {
    for file in $@;
        do
            echo $file
        done
}

$@ is a special reference to ALL arguments passed to the function.

So if we run this:

func_name this.txt that.md and.html the.css other.yml

It would print each file name on a newline. The arguments need to be space separated.

I think from the above you could adapt it to your needs.

Someone may come and offer a different thing. My knowledge of bash is a bit limited.

Collapse
 
stephencweiss profile image
Stephen Charles Weiss

Thanks Dan! I'll try that out :)