Skip to main content
added 2 characters in body
Source Link
jherran
  • 4k
  • 3
  • 25
  • 34

Try this way:

cpfromserver () {
    files=''
    for x in "$@"
    do
        files="$files /some/location/$x/$x.txt /some/location/$x/$x.pdf"
    done
    scp [email protected]:"$files" /somewhere/else/
}

Important caveat from commentsImportant caveat from comments: "It's worth noting for posterity that this solution definitely won't work for complicated filenames. If a filename contains a space, or a newline, or quotes, this approach will definitely fail."

Try this way:

cpfromserver () {
    files=''
    for x in "$@"
    do
        files="$files /some/location/$x/$x.txt /some/location/$x/$x.pdf"
    done
    scp [email protected]:"$files" /somewhere/else/
}

Important caveat from comments: "It's worth noting for posterity that this solution definitely won't work for complicated filenames. If a filename contains a space, or a newline, or quotes, this approach will definitely fail."

Try this way:

cpfromserver () {
    files=''
    for x in "$@"
    do
        files="$files /some/location/$x/$x.txt /some/location/$x/$x.pdf"
    done
    scp [email protected]:"$files" /somewhere/else/
}

Important caveat from comments: "It's worth noting for posterity that this solution definitely won't work for complicated filenames. If a filename contains a space, or a newline, or quotes, this approach will definitely fail."

Try this way:

cpfromserver () {
    files=''
    for x in "$@"
    do
        files="$files /some/location/$x/$x.txt /some/location/$x/$x.pdf"
    done
    scp [email protected]:"$files" /somewhere/else/
}

Important caveat from comments: "It's worth noting for posterity that this solution definitely won't work for complicated filenames. If a filename contains a space, or a newline, or quotes, this approach will definitely fail."

Try this way:

cpfromserver () {
    files=''
    for x in "$@"
    do
        files="$files /some/location/$x/$x.txt /some/location/$x/$x.pdf"
    done
    scp [email protected]:"$files" /somewhere/else/
}

Try this way:

cpfromserver () {
    files=''
    for x in "$@"
    do
        files="$files /some/location/$x/$x.txt /some/location/$x/$x.pdf"
    done
    scp [email protected]:"$files" /somewhere/else/
}

Important caveat from comments: "It's worth noting for posterity that this solution definitely won't work for complicated filenames. If a filename contains a space, or a newline, or quotes, this approach will definitely fail."

added 2 characters in body
Source Link
muru
  • 77.9k
  • 16
  • 212
  • 318

Try this way:

cpfromserver () {
    files=''
    for x in $@"$@"
    do
        files="$files /some/location/$x/$x.txt /some/location/$x/$x.pdf"
    done
    scp [email protected]:"$files" /somewhere/else/
}

Try this way:

cpfromserver () {
    files=''
    for x in $@
    do
        files="$files /some/location/$x/$x.txt /some/location/$x/$x.pdf"
    done
    scp [email protected]:"$files" /somewhere/else/
}

Try this way:

cpfromserver () {
    files=''
    for x in "$@"
    do
        files="$files /some/location/$x/$x.txt /some/location/$x/$x.pdf"
    done
    scp [email protected]:"$files" /somewhere/else/
}
Source Link
jherran
  • 4k
  • 3
  • 25
  • 34
Loading