Whoud anybody explain the reason to have such construction in code: ${1+"$@"}
It is used in the function that replasing functionality of the 'cd' command by processing the 'cd' itself and after that processing some other stuff:
I understand it intends to aply function parameters to the 'cd' command.
I do not understand NEEDS for that extra-smartness.
Why not just '$*' or '$@'?
Also I am not clear about that syntaxis: I see it use the first parameter: $1, ${1}; but the '+"..."' - what is it?
If that is kind of concatenation, the "$@" - means all parameters (as set of words, I guess); so it would duplicate the first parameter: it is already mentioned before '+' and also included in $@; but, not, it is not repeating.
If someone could explain what is used here and what is the benefit from that sysntax, I will appreciate!
Thanks ctsgnb for that link: very usefull (I familiar with most of that from bash-man pages, but from O'Relly it is much better!)
But nothing is explained!
I see that the ${1+"$@"} would be all parameters if $1 exist or nothing, if not.
SO WHAT?!
What is the reason to have that?!!?
The '$*' or '$@' would do the same!
What the point?
Last edited by alex_5161; 01-19-2011 at 02:56 PM..
I guess it is to cover the case where the directory has some space or tab in its name or something like this, or maybe for compatible reason with some OS
oops...
Oh .... ok now i understand your question ...
What is the benefit from ${1+"$@"} notation intead of just "$@" ?
I dunnot .
Error detection on empty var may be different between $1 and $@ on some unix ??? i have no idea ... maybe having a look at the rest of the code could give some clue ?
But so far, i have no idea ...
Once again, Thanks ctsgnb for replay!
Appreciate to see your thoughts.
... some space or tab .. - OK, reasonable to apply the $@; so it would keep the word with spase as one word!
Good point!
Anything else is not a case, as I see it here: followed code (just couple line to set the 'prompt') have no relation to first 'cd' command; all other guesses are not reasonable in here (unless the code was used from some source where other your points could be meaningfull.)
I have check situation with a space and a new line in the dir-name. Here is the test-code and results:
So, by this testing the '\cd "$@" ' is completely suffisient. Most important, it is strait forward with nothing extra; no extra functionality, no questions.
Maybe anybody see anything else that would be a reason to have 'cd' ${1+"$@"} instead of the \cd "$@" ?
Thanks!
---------- Post updated 01-20-11 at 01:08 PM ---------- Previous update was 01-19-11 at 03:53 PM ----------
I have the answer from another place: here
and this question was discussed also here2
Shortly, that syntax provide appropriate 'cd' functionality with no-arguments when "$@" for no-arguments returned empty string, instead of 'nothing' (as it was 20 years ago.)
cd - with 'nothing' change to home-dir;
cd "" - with empty string stay in current dir (so, it is the >cd . )
But today the "$@" return correctly nothing and 'cd' will process "$@" appropriately.
Hello.
System : opensuse leap 42.3
I have a bash script that build a text file.
I would like the last command doing :
print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt
where :
print_cmd ::= some printing... (1 Reply)
Hi Guys,
I'm sorry but I can't find answer for this, what is the meaning of -s option in "if" statement on unix scipting. Please see sample below:
opath=/home/output
for i in N1 N2 N3 N4
do
echo $i
if
then
grep $i $opath/N5_CRAI > $opath/N5_$i.crai
chmod 777 $opath/N5_$i.crai
... (7 Replies)
Hi, What means "##*", "% *" in a variable??
I have this in the script that i'm reading:
...
read line
echo $line
echo ${line#* }
echo ${line##* }
echo ${line% * }
...
The first print:
DN: RCROOT ONRM_ROOT_MO SNW ONRM_ROOT_MO BSC BSCCC2 BTS ALTOHATILLONOR
The second print:... (2 Replies)
Hi,
I have line in input file as below:
3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL
My expected output for line in the file must be :
"1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL"
Can someone... (7 Replies)
I need to sort the following file by the rhdiskpower devices in the last column:
Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path
1024 851 1024 OCRVOT1_0000 OCRVOT1_0000 System UNKNOWN ... (3 Replies)
Hi,
I am new into UNIX shell scripting and I am wondering what is the meaning of the below text which appears at the end of each line in the ".sh" file:
> /dev/null 2>&1
For example, the line below:
sh $HOME/stats/Rep777/Act_777.sh omc omc > /dev/null 2>&1
I know for sure what "sh... (10 Replies)
Hi,
Could someone pls help me on the below command:
if
then
------------------
------------
fi
if
then
-------------
-------------------
-------------------
fi
What does this signify?
Thanks,
.. (4 Replies)
while (my $row = $sth->fetchrow_arrayref) {
$var->{"@$row"}=" ";
}
Can anyone help me understanding above mentioned.
i) As per my knowledge $row is taking ARRAY Refernce from the database
ii) @$row is containing the value of 0th index of the array, testted the same.
but I am not able... (0 Replies)