Sponsored Content
Full Discussion: Strange type mistake?!
Top Forums Shell Programming and Scripting Strange type mistake?! Post 302913345 by Corona688 on Friday 15th of August 2014 11:46:32 AM
Old 08-15-2014
Oh! I'd missed the IFS! That's very important.

That's almost certainly related to your issue... IFS controls all splitting! So your script is effectively being forcefed each element as one parameter like:

Code:
./script "-N 0 -m 0"

instead of being split like you'd want, into

Code:
./script "-N" "0" "-m" "0"

...because that string contains no single-quotes to split upon.

Anyway, you don't need to set IFS here at all. It only controls how unquoted strings work in an array, it has nothing to do with the behavior of quotes themselves. Just be sure to quote your variables where you don't want them to split!

Code:
CONFIGURATION_ARRAY=( '-N 0 -m 0' '-N 0 -m 1'  )

for configuration in "${CONFIGURATION_ARRAY[@]}"
do
        printf "Quoted does not split: %s\n" "$configuration"
        printf "Unquoted split:  %s\n" $configuration
done

The quotes in red are special. When you put double-quotes around $@ or ${ARRAY[@]} it splits on array elements and not IFS.

This outputs:

Code:
Quoted does not split: -N 0 -m 0
Unquoted split:  -N
Unquoted split:  0
Unquoted split:  -m
Unquoted split:  0
Quoted does not split: -N 0 -m 1
Unquoted split:  -N
Unquoted split:  0
Unquoted split:  -m
Unquoted split:  1


Last edited by Corona688; 08-15-2014 at 12:55 PM..
This User Gave Thanks to Corona688 For This Post:
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Crontab Mistake!!!

Hi. I hope someone can help me with this problem. Being a novice to Unix, I editted my crontab directly by typing " crontab -e ". Well, I needed to make some changes so, I typed " crontab -r ". Now I have no crontab, and I can't seem to get crontab to write a new file. I' ve tried: vi... (4 Replies)
Discussion started by: cstovall
4 Replies

2. Shell Programming and Scripting

String type to date type

Can one string type variable changed into the date type variable. (1 Reply)
Discussion started by: rinku
1 Replies

3. Programming

array type has incomplete element type

Dear colleagues, One of my friend have a problem with c code. While compiling a c program it displays a message like "array type has incomplete element type". Any body can provide a solution for it. Jaganadh.G (1 Reply)
Discussion started by: jaganadh
1 Replies

4. AIX

Did a Mistake with HACMP

Hi, I needed space on a FS, and when I've added the space on the filesystem, I did it trough the regular smitty fs inteface and not with smitty cl_lvm. Can someone help me to repair the situat before a faileover happen ? Thanks for your help,:mad: (13 Replies)
Discussion started by: azzed27
13 Replies

5. Shell Programming and Scripting

Is there any mistake in this code:

cat $1 | sort -n | uniq | $1 in other words, I sort the content of the file and put the ouput in the same file, is there any mistakes in this cshell code ??? (4 Replies)
Discussion started by: Takeeshe
4 Replies

6. UNIX for Dummies Questions & Answers

Probably some stupid mistake...

Hi everyone ! I have a file wich look like this : >Sis01 > Sis02 ... >Sis44 I want to separe each paragraphe in a different file, so I decide to use the "FOR" loop + sed. for f in {01..44} do (5 Replies)
Discussion started by: sluvah
5 Replies

7. UNIX for Dummies Questions & Answers

Can anyone help me to spot my mistake?

Hi there can anyone help me to spot my mistake and please explain why it appears My code : #!/usr/bin/gawk -f BEGIN { bytes =0} { temp=$(grep "datafeed\.php" | cut -d" " -f8) bytes += temp} END { printf "Number of bytes: %d\n", bytes } when I am running ./q411 an411 an411: ... (6 Replies)
Discussion started by: FUTURE_EINSTEIN
6 Replies

8. Programming

Strange value of the double type variable: -nan(0x8000000000000)

I am confused by the value of "currdisk->currangle" after adding operation. Initially the value of "currdisk->currangle" is 0.77500000000000013, but after adding operation, it's changed to "-nan(0x8000000000000)", Can anyone explain ? Thanks! The following is the occasion of gdb debugging. 3338 ... (8 Replies)
Discussion started by: 915086731
8 Replies
VTYSH(1)							   Version 0.88 							  VTYSH(1)

NAME
vtysh - a integrated shell for Zebra routing software SYNOPSIS
vtysh [ -e command ] DESCBGPTION
vtysh is a integrated shell for Zebra routing engine. OPTIONS
-e Specify command to be executed under batch mode. COMMANDS
Almost Zebra commands. ping traceroute telnnet start-shell start-shell bash start-shell zsh FILES
/usr/local/etc/Zebra.conf The default location of the vtysh config file. WARNING
This man page is intended as a quick reference for command line options, and for config file commands. The definitive document is the Info file Zebra. SEE ALSO
References to other related man pages: bgpd(8), ripd(8), ripngd(8), ospfd(8), ospf6d(8), zebra(8) BUGS
vtysh eats bugs for breakfast. If you have food for the maintainers try <bug-zebra@gnu.org> AUTHOR
[S] See <www.zebra.org>, or the Info file for an accurate list of authors. Zebra Beast - VTY shell July 2000 VTYSH(1)
All times are GMT -4. The time now is 10:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy