Copy files with bash scriptBash source — select the right function when two sourced files have the same...

In what sequence should an advanced civilization teach technology to medieval society to maximize rate of adoption?

sed replacing character in a file

In what state are satellites left in when they are left in a graveyard orbit?

Are there any rules about taking damage whilst holding your breath in combat?

Can I see Harvest moon in India?

What makes a smart phone "kosher"?

If a space ship entered Earth orbit, how likely is it to be seen?

Is there a tool to measure the "maturity" of a code in Git?

Can a character with good/neutral alignment attune to a sentient object with evil alignment?

How do I say "quirky" in German without sounding derogatory?

How To Make Earth's Oceans as Brackish as Lyr's

Output a Super Mario Image

ColorFunction based on array index in ListLinePlot

Does a succubus' charm end when it dies?

A Mainer Expression

Is there any way to land a rover on the Moon without using any thrusters?

Some Prime Peerage

Add text inside circuit component in circuitikz environment

Why don't airports use arresting gears to recover energy from landing passenger planes?

Can I conceal an antihero's insanity - and should I?

Can Feather bring back a spell with Jump-Start?

How to control the output voltage of a solid state relay

Consonance v. Dissonance

Has SHA256 been broken by Treadwell Stanton DuPont?



Copy files with bash script


Bash source — select the right function when two sourced files have the same function name?bash completion not working for one userBack-up script via bash — issues with file paths?How to pass an argument from a bash script to 'x-terminal-emulator -e bash -c'?Bash script - run application and show live outputBash script to pass arguments to a scriptFind words after specific symbol on lineHow can I pass two files through ssh?Running multiple instances of perl via xargs






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I want to pass four parameters to bash script. script should copy files in user home directory.



/opt/script.sh f1 f2 f3 f4


FYI: 1-each file might be exist or not, might be one of them exist or four of them.
2- every time run script might call all or one of them like this:



/opt/script.sh f1 

/opt/script.sh f1 f4


Here is my script, it always copy f1 and seems only one of them [if] execute!



#!/bin/bash
for var in "$@" ; do
T1=$1
T2=$2
if [ $T1 = "f1" ]; then
cp file1 /home/users
else
if [ $T2 = "f2" ]; then
cp file2 /home/users
....
fi
fi
done









share|improve this question



























  • 1. what is it that you are trying to do? 2. why are you looping over "$@" and then completely ignoring $var in the loop and setting T1 and T2 to $1 and $2 respectively? maybe you should be using a case statement instead.

    – cas
    4 mins ago


















0















I want to pass four parameters to bash script. script should copy files in user home directory.



/opt/script.sh f1 f2 f3 f4


FYI: 1-each file might be exist or not, might be one of them exist or four of them.
2- every time run script might call all or one of them like this:



/opt/script.sh f1 

/opt/script.sh f1 f4


Here is my script, it always copy f1 and seems only one of them [if] execute!



#!/bin/bash
for var in "$@" ; do
T1=$1
T2=$2
if [ $T1 = "f1" ]; then
cp file1 /home/users
else
if [ $T2 = "f2" ]; then
cp file2 /home/users
....
fi
fi
done









share|improve this question



























  • 1. what is it that you are trying to do? 2. why are you looping over "$@" and then completely ignoring $var in the loop and setting T1 and T2 to $1 and $2 respectively? maybe you should be using a case statement instead.

    – cas
    4 mins ago














0












0








0








I want to pass four parameters to bash script. script should copy files in user home directory.



/opt/script.sh f1 f2 f3 f4


FYI: 1-each file might be exist or not, might be one of them exist or four of them.
2- every time run script might call all or one of them like this:



/opt/script.sh f1 

/opt/script.sh f1 f4


Here is my script, it always copy f1 and seems only one of them [if] execute!



#!/bin/bash
for var in "$@" ; do
T1=$1
T2=$2
if [ $T1 = "f1" ]; then
cp file1 /home/users
else
if [ $T2 = "f2" ]; then
cp file2 /home/users
....
fi
fi
done









share|improve this question
















I want to pass four parameters to bash script. script should copy files in user home directory.



/opt/script.sh f1 f2 f3 f4


FYI: 1-each file might be exist or not, might be one of them exist or four of them.
2- every time run script might call all or one of them like this:



/opt/script.sh f1 

/opt/script.sh f1 f4


Here is my script, it always copy f1 and seems only one of them [if] execute!



#!/bin/bash
for var in "$@" ; do
T1=$1
T2=$2
if [ $T1 = "f1" ]; then
cp file1 /home/users
else
if [ $T2 = "f2" ]; then
cp file2 /home/users
....
fi
fi
done






bash shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 mins ago









cas

43.5k4 gold badges63 silver badges114 bronze badges




43.5k4 gold badges63 silver badges114 bronze badges










asked 21 mins ago









MehrdadMehrdad

94 bronze badges




94 bronze badges
















  • 1. what is it that you are trying to do? 2. why are you looping over "$@" and then completely ignoring $var in the loop and setting T1 and T2 to $1 and $2 respectively? maybe you should be using a case statement instead.

    – cas
    4 mins ago



















  • 1. what is it that you are trying to do? 2. why are you looping over "$@" and then completely ignoring $var in the loop and setting T1 and T2 to $1 and $2 respectively? maybe you should be using a case statement instead.

    – cas
    4 mins ago

















1. what is it that you are trying to do? 2. why are you looping over "$@" and then completely ignoring $var in the loop and setting T1 and T2 to $1 and $2 respectively? maybe you should be using a case statement instead.

– cas
4 mins ago





1. what is it that you are trying to do? 2. why are you looping over "$@" and then completely ignoring $var in the loop and setting T1 and T2 to $1 and $2 respectively? maybe you should be using a case statement instead.

– cas
4 mins ago










0






active

oldest

votes














Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});















draft saved

draft discarded
















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f541686%2fcopy-files-with-bash-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

















draft saved

draft discarded



















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f541686%2fcopy-files-with-bash-script%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...