LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-21-2016, 04:40 AM   #1
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73
Special characters in bash


Hello, I've got a script which uses an array, something like this:

Code:
array_1=("test-1" "test-2" "test-3")
but under some conditions (I don't know the conditions), if I use 'for', like this:

Code:
for item in ${array_1[@]}; do
    some_code
done
it doesn't go properly thru the array, is it possible that character '-' can influence the code?

If I drop '-' from the item of the array, it behaves properly. I can't really explain better then this, coz I can't see the issue and can't figure out if this is due to '-' in the items or just weird /bin/sh or /bin/bash issue.

Thanks!

Last edited by robertjinx; 06-21-2016 at 05:25 AM.
 
Old 06-21-2016, 05:10 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,792

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
try array_1 instead of arrar_1
 
Old 06-21-2016, 05:24 AM   #3
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Original Poster
Rep: Reputation: 73
That was a typo, still doesn't answer my question.
 
Old 06-21-2016, 06:20 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,792

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
it works for me, so probably something wrong with that "some code".
You also may try to use "" around the variables.
 
Old 06-21-2016, 07:45 AM   #5
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Original Poster
Rep: Reputation: 73
Yes, adding '"' seems to be a bit better now, but not 100% sure. Will test more.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Search string on pattern of special characters Bash rbees Programming 10 03-23-2015 04:59 PM
[SOLVED] Bash - escape all special characters in variable string? arashi256 Linux - Newbie 10 01-23-2012 09:43 AM
How do I replace special characters in a string within a bash script? rhaup0317 Linux - Newbie 2 06-03-2008 11:56 AM
bash command for removing special characters from string kkpal Linux - Newbie 5 05-26-2008 08:14 AM
bash and filenames with special characters CoolAJ86 Programming 2 03-09-2005 02:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration