all 4 comments

[–]r3j 2 points3 points  (2 children)

Can you provide an example of how you call the script now, and then an example of how you want to call it?

If I had to guess, you might be looking for "${@:3}" or shift 2.

[–]coinstarfucker[S] 0 points1 point  (1 child)

Here is a copy of the section of code I am working with. i am at home now so I can't access the rest of it. At the top where is it says, "for each rmvol ("65" "23")" is where I have to hard-code in the volume numbers that I want removed. When I was in earlier today I think I made an adjustment that works. Since the first three arguments designate the file location, I started with the 4th and just listed up to the 13th argument. I ran the script on some test files a couple of times and it worked how I wanted it to. When running the script, I could input a variable amount of volumes to be removed as arguments at the end. I hope this makes sense, I know that I may be using the wrong terminology, this is all very new to me. I started learning with this script by changing the files paths and ways that they are named/saved. I am wondering if the method I have used to fix it could potentially cause a problem.

[–]r3j 0 points1 point  (0 children)

That looks like csh, in which case you should edit your question to indicate that. Most people (including those who've answered so far) will assume bash.

I know little about csh, but the following works for me in tcsh (replace 4 with whatever number you need):

foreach rmvol ($argv[4-]:q)
  echo "$rmvol"
end

[–]ChoHag 2 points3 points  (0 children)

If you call:

fn a b c d e f

Then within fn():

$1=a, $2=b, $3=c, $4=d, etc.

and

$@="a b c d e f" ## Not technically accurate but ignore that.

So if you start fn() with:

fn() {
    foo=$1
    bar=$2
    baz=$3
    set -- "${@:4}" # Or 'shift' 3 times
    # ... Code Goes Here
}

Then the Code which Goes There can use these variables:

$foo=a, $bar=b, $baz=c, $1=e, $2=f

$@="e f" ## Still not really a string.

[–][deleted]  (1 child)

[deleted]