Sponsored Content
Top Forums UNIX for Advanced & Expert Users meaning of the construction: ${1+"$@"} ? Post 302489141 by alex_5161 on Thursday 20th of January 2011 12:08:00 PM
Old 01-20-2011
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:
Code:
> typeset -f tst
tst ()
{
    cdir=$(pwd);
    echo "starting in >${cdir}< directory.";
    echo "<"${1+$@}">";
    echo "\$@ is:"$@"<";
    \cd $@;
    echo "after \\cd \$@; now in $(pwd)";
    chdir $cdir;
    \cd ${1+$@};
    echo "after \\cd \${1+\$@}; now in $(pwd)";
    chdir $cdir;
    'cd' ${1+"$@"};
    echo "after 'cd' \${1+\"\$@\"}; now in $(pwd)";
    chdir $cdir;
    \cd "$@";
    echo "after \\cd \"\$@\"; now in $(pwd)";
    chdir $cdir
}
P> mkdir TST_dir "TST dir" "TST
> dir"
>
> tst TST_dir
starting in >/export/home/dca/TMP< directory.
<TST_dir>
$@ is:TST_dir<
after \cd $@; now in /export/home/dca/TMP/TST_dir
after \cd ${1+$@}; now in /export/home/dca/TMP/TST_dir
after 'cd' ${1+"$@"}; now in /export/home/dca/TMP/TST_dir
after \cd "$@"; now in /export/home/dca/TMP/TST_dir
> tst "TST dir"
starting in >/export/home/dca/TMP< directory.
<TST dir>
$@ is:TST dir<
bash: cd: TST: No such file or directory
after \cd $@; now in /export/home/dca/TMP
bash: cd: TST: No such file or directory
after \cd ${1+$@}; now in /export/home/dca/TMP
after 'cd' ${1+"$@"}; now in /export/home/dca/TMP/TST dir
after \cd "$@"; now in /export/home/dca/TMP/TST dir
> tst "TST
> dir"
starting in >/export/home/dca/TMP< directory.
<TST dir>
$@ is:TST dir<
bash: cd: TST: No such file or directory
after \cd $@; now in /export/home/dca/TMP
bash: cd: TST: No such file or directory
after \cd ${1+$@}; now in /export/home/dca/TMP
after 'cd' ${1+"$@"}; now in /export/home/dca/TMP/TST
dir
after \cd "$@"; now in /export/home/dca/TMP/TST
dir

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.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Meaning of $var->{"@$row[0]"}=" "; ???

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)
Discussion started by: jaigs_27
0 Replies

2. Shell Programming and Scripting

Meaning of "if [ -x /opt/OV/bin/ovpolicy ]"

Hi, Could someone pls help me on the below command: if then ------------------ ------------ fi if then ------------- ------------------- ------------------- fi What does this signify? Thanks, .. (4 Replies)
Discussion started by: ww26683
4 Replies

3. Shell Programming and Scripting

Meaning of "> /dev/null 2>&1"

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)
Discussion started by: salanalani
10 Replies

4. UNIX for Dummies Questions & Answers

the meaning of "!:*" in "alias foo 'command\!:*' filename"

Hi: How can I remove my own post? Thanks. (2 Replies)
Discussion started by: phil518
2 Replies

5. Shell Programming and Scripting

Meaning of "b" modifier in "sort" command

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)
Discussion started by: wjssj
3 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

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)
Discussion started by: shis100
7 Replies

7. UNIX for Dummies Questions & Answers

Variable "##*", "% *" meaning

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)
Discussion started by: darocham
2 Replies

8. UNIX for Dummies Questions & Answers

What is the meaning of "-s" option in "if" statement?

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)
Discussion started by: rymnd_12345
7 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

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)
Discussion started by: jcdole
1 Replies
SHTOOL-FIXPERM.TMP(1)					      GNU Portable Shell Tool					     SHTOOL-FIXPERM.TMP(1)

NAME
shtool-fixperm - GNU shtool file permission fixing command SYNOPSIS
shtool fixperm [-v|--verbose] [-t|--trace] path [path ...] DESCRIPTION
shtool fixperm fixes file permissions inside a source tree under path by cleaning up the permission bits. It determines the cleaned up permission from the already set bits. It is intended to be run before a tarball is rolled (usually with shtool tarball) out of a source tree. The trick is that this is more convenient than having to set the permissions manually or by using a large file list. OPTIONS
The following command line options are available. -v, --verbose Display some processing information. -t, --trace Enable the output of the essential shell commands which are executed. EXAMPLE
# Makefile.in dist: shtool fixperm -v * ... HISTORY
The GNU shtool fixperm command was originally written by Ralf S. Engelschall <rse@engelschall.com> in 1996 for OSSP eperl. It was later taken over into GNU shtool. SEE ALSO
shtool(1), chmod(1). 18-Jul-2008 shtool 2.0.8 SHTOOL-FIXPERM.TMP(1)
All times are GMT -4. The time now is 06:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy