LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   what is lighter on the system, variable calls, or full path in BASH script? (https://www.linuxquestions.org/questions/linux-newbie-8/what-is-lighter-on-the-system-variable-calls-or-full-path-in-bash-script-947568/)

lleb 05-30-2012 07:30 AM

what is lighter on the system, variable calls, or full path in BASH script?
 
example:
Code:

#!/bin/bash
OLD=/tmp/old
LOCAL=`pwd`
cp -Ravf $OLD/foo.* $LOCAL

or
Code:

#!/bin/bash
LOCAL=`pwd`
cp -Ravf /tmp/old/foo.* $LOCAL

This is just an example, but if i were to use the 2nd option to copy say 30-40 specific files/types of files would that be lighter on the system, then the option with 1 variables, or does it really matter. typically this would be run ONCE on a system to transfer data from old computer to new.

pan64 05-30-2012 07:37 AM

in case you want to copy 30-40 files (or less than a few thousands) it does not matter at all.
variables are used to write better scripts (which can be handled easier)

schneidz 05-30-2012 09:40 AM

variables are stored in ram.

lleb 05-30-2012 12:39 PM

Quote:

Originally Posted by pan64 (Post 4691138)
in case you want to copy 30-40 files (or less than a few thousands) it does not matter at all.
variables are used to write better scripts (which can be handled easier)

let me be more specific, there can be thousands of files, but we are talking file type extension, etc... like .dat and .idx from the data base, etc...

if it really does not matter, then ill leave it in simple plan text without creating any functions, or what not.

Thank you both.

pan64 05-30-2012 12:45 PM

I think it really does not matter, copying files will take much more time






__________________________________
Happy with solution ... mark as SOLVED
If someone helps you, or you approve of what's posted, click the "Add to Reputation" button, on the left of the post.

suicidaleggroll 05-30-2012 12:47 PM

The variable expansion is only performed once on the call to copy, it doesn't matter how many files are actually copied. If you're only calling the copy 30-40 times, then you're only doing the variable expansion 30-40 times, and it will have no effect on the speed of the process. If this was inside a high speed loop that was iterating thousands/millions of times in a matter of seconds, then it might start to make a difference, but the copy itself will use FAR more time than the variable expansion in this case, so it'll make no practical difference.

lleb 05-30-2012 12:53 PM

fantastic, thanks all.


All times are GMT -5. The time now is 03:54 PM.