Fedora Linux Support Community & Resources Center
  #1  
Old 4th December 2012, 04:52 PM
sea's Avatar
sea Online
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,600
linuxfedorachrome
[BASH]: variable empty at random?

Hello Community,

I'm quite confused about my current scripting issue...
I source a file wich contains some variables, like "ks_name=Awesome".
Then i echo some of the content, to verify its not empty, works...

But when i add multiple varibales together, the resulting variable is empty, eventhough i had added hardcoded text?!?

Here's the output:
Code:
# | Fedora : Script Tools 0.7.2 : root (0)                                          sa kick Awesome m : 2012.12.04-17.48.43 | #
# |                                              sea's Kickstart Handler (0.3)                                              | #
# | Selected project:                                                                                               Awesome | #
# |                                     Kickstart generator (0.3) for project: Awesome                                     | #
Awesome /home/simon/.config/script-tools/kickstarts
# | Saving kickstart:                                                                                               Awesome | #
# | File:                                                                                                                   | #
/usr/share/script-tools/Included_Functions/module.dev.prj.ks: line 124: $output: ambiguous redirect
# | Parsing: 00_header...
See the line without the starting "# |" where there is Awesome, and the path?
And the line starting with File: but righthand side is empty?

The 'original' variables are NOT empty, but placing them together results in an empty string?

Thats the echo of the script below and the issue i face.
Code:
#
	#	Title
	#
		[ "" = "$1" ] && lbl=$(KS_Prj_Select) || lbl="$1"
		sT "Kickstart generator ($script_version) for project: $lbl"
	#
	#	Variables
	#
		workdir=$SEA_DEV_DIR/$lbl/ks
		source $(dirname $workdir)/kickstart

		echo $ks_name $SEA_KS_DIR
		today="$(date +'%Y%m%d-%H%M')"
		
		output="bully hit:: $SEA_KS_DIR/$lbl-$today.ks"
		sE "Saving kickstart:" "$lbl"
		sE "File:"	"$output"
The variable output is empty, therefor the output to it results in an error with ambiguous redirect.
Even the plain text seems to be removed from the variable $output

Every hint or idea very welcome
Thank you in advance.
Simon
Reply With Quote
  #2  
Old 4th December 2012, 06:46 PM
marko's Avatar
marko Online
Registered User
 
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 5,445
linuxfirefox
Re: [BASH]: variable empty at random?

Do you have a simple example script that I can run here? I see a lot of stuff in there like "sE" and "sT" which I have no idea what they are.

I would think sE is some kind of kickstart subroutine for text handling and you're using them
as if they accept multiple inputs, this like $1 $2 .... $n
My guess is that "sE" only can parse a single input and has to take a complex string (ie has spaces) as a quoted string:

Try this:
Quote:
sE "Saving kickstart: $lbl"
sE "File: $output"
Reply With Quote
  #3  
Old 4th December 2012, 08:42 PM
sea's Avatar
sea Online
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,600
linuxfedorachrome
Re: [BASH]: variable empty at random?

You could alias/replace them with "echo" or printf for sP accordingly.
sE and sP are kind of optimized for 2 inputs to be shown, but can handle up to 7, but starts breaking layout after 3-4 values. As long there is no REGEX nor escape chars in the string to be displayed, the value is ususaly shown properly, and valid variable and path string combination belongs to the things that it can display without issues (but beeing longer than the screen).
/* EDIT: If interested in the code, around line 217-321: http://fpaste.org/SrnO/ */

It seemed that the variable name 'output' was reserved, because adding the same strings to another varablename did solve the problem.
Just weird, i thought i had used this variable name for the same situation at previous times.

Now i changed it to:
Code:
	#
	#	Variables
	#
		workdir=$SEA_DEV_DIR/$lbl/ks
		source $(dirname $workdir)/kickstart
		today="$(date +'%Y%m%d-%H%M')"
		
		tmp=$SEA_KS_DIR/$ks_name-$today.ks	
		thisFile=$tmp
		
		#sE "Saving kickstart:" "$lbl"
		sE "File:"	"$thisFile"
and its working as expected, sry didnt thought that the name of a variable would matter that much...

Last edited by sea; 4th December 2012 at 09:04 PM.
Reply With Quote
  #4  
Old 5th December 2012, 04:42 AM
stevea's Avatar
stevea Offline
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,298
linuxfirefox
Re: [BASH]: variable empty at random?

THIS THREAD IS NOT SOLVED!

No you certainly cannot replace sE with echo and still get that error message.

Sorry sea, but you've failed to provide enough info for anyone to tell what is wrong.
Marko had a pretty good guess at what it might be.
You've given no evidence that output is empty, defined, undefined or anything else.

Have you learned to do shell debugging with all your extensive and ornate scripts ?
set -x
is a good start.

Quote:
It seemed that the variable name 'output' was reserved, because adding the same strings to another varablename did solve the problem.
NO! Wrong. You should not spread misinformation. You foul your own thinking when you misinform yourself; you foul your reputation and harm others when you spread misinformation. You are just making things up to evade finding the actual cause of the problem.

First learn to use the correct terminology b/c bad language leads to bad thinking. You are NOT "adding" strings. You are forming a complex command line and you are failing to understand exactly how it is being evaluated. Bash command line evaluation is quite complex, no shame in being confused.

Maybe this will help your thinking,
Code:
countem () 
{ 
    echo "arg count = $#";
    for ((i=1; $#>0; i++))
    do
        echo "$i: [$1]";
        shift;
    done
}

Code:
[stevea@crucibulum Desktop]$ countem a b c d
arg count = 4
1: [a]
2: [b]
3: [c]
4: [d]
[stevea@crucibulum Desktop]$ countem "a b c d"
arg count = 1
1: [a b c d]
[stevea@crucibulum Desktop]$ countem "a b" "c d"
arg count = 2
1: [a b]
2: [c d]
[stevea@crucibulum Desktop]$
What this means is that each command line arguments by first expanding any variables, and passing each arg separately - where args are separated by an IFS char not withing quotes. It is NOT ADDED and NOT CONCATENATED.

Now when those individual args (which may contain an IFS char) are re-evaluated by the SE or sT functions or commands - you must very careful to understand that the IFS are RE-evaluted.
Code:
[stevea@crucibulum Desktop]$ call_countem() { countem $* ; }
[stevea@crucibulum Desktop]$ countem "a b " "c d"
arg count = 2
1: [a b ]
2: [c d]
[stevea@crucibulum Desktop]$ call_countem "a b " "c d"
arg count = 4
1: [a]
2: [b]
3: [c]
4: [d]
But bash provides ways around this ...

Code:
[stevea@crucibulum Desktop]$ call_countem2() { countem "$@" ; }
[stevea@crucibulum Desktop]$ call_countem2 "a b" "c d"
arg count = 2
1: [a b]
2: [c d]
What do you think this does ?
Code:
[stevea@crucibulum Desktop]$ QT='"'
[stevea@crucibulum Desktop]$ call_countem $QT "help me" $QT
Do you understand why this gives a different result ?
Code:
[stevea@crucibulum Desktop]$ eval call_countem $QT "help me" $QT
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe

Last edited by stevea; 5th December 2012 at 04:46 AM.
Reply With Quote
  #5  
Old 5th December 2012, 01:18 PM
sea's Avatar
sea Online
"Shells" (of a sub world)
 
Join Date: May 2011
Location: Helvetic Federation (Swissh)
Age: 33
Posts: 2,600
linuxfedorachrome
Re: [BASH]: variable empty at random?

Stevea,
Thank you, but i'm not quite getting your point, at least i'm not sure of.
No, i havent (really) learned about shell debugging.
Allthough i've seen "set -x" previously, i'm not used to use it.
Specialy as it breaks the 'design' of my scripts massivly and in a very intrusive way.

Are there any IFS chars in the variables i had passed to form $output?
I'm not aware of this.

And yes, to me its quite confusing, and were inaccurate (as i figured now).
I could echo $output, but couldnt sE it, because sE (acutaly sP - printf) works with an internal variable named $outptut.

Oh oh.. i see, you lead me towards to having a closer look at the sP function, which cleared the output variable... that happend on line 225, but wernt used at all
Still, i thought bash differs from 'internal' and 'external' vairables eventhough they have the same name?

Anyhow, this seems to be the cause i couldnt sE $output, as it got cleared within the function.
Reply With Quote
Reply

Tags
bash, random, variable

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How does bash handle array variable? youhaodeyi Using Fedora 8 26th November 2008 03:34 AM
bash $?: what is the $? variable? gold Using Fedora 2 1st January 2008 04:27 AM
Calling a variable from a file BASH script Thoreau Programming & Packaging 16 9th January 2007 07:46 PM
[bash-script] regex variable carramba Programming & Packaging 1 1st July 2006 05:46 PM


Current GMT-time: 00:53 (Sunday, 19-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat