I have a config file that needs to be formatted before it's sourced to a script. I've been formatting it with sed and dropping it in /tmp then sourcing it from there.
I'd like to just format the config file with sed then declare the variables without having to create a temporary file in /tmp. So I tried a loop like this ...
This works fine except when $var_value contains a value that appends itself with another variable that should have been declared already. For example, when it formats my config file and runs through the loop I have it echo a few variables it declared at the end. I end up with ...
As you can see from my original loop, I used sed to format $var_value to remove the quotations...which seems a little odd to have to do in the first place. So perhaps I don't fully understand how declare is working? Is this simply a limitation that I cannot get around?
I have a config file that needs to be formatted before it's sourced to a script. I've been formatting it with sed and dropping it in /tmp then sourcing it from there.
What is the format of the config file? Why do you have to change it?
Quote:
I'd like to just format the config file with sed then declare the variables without having to create a temporary file in /tmp. So I tried a loop like this ...
Why are you using declare? It's not necessary.
Quote:
This works fine except when $var_value contains a value that appends itself with another variable that should have been declared already. For example, when it formats my config file and runs through the loop I have it echo a few variables it declared at the end. I end up with ...
As you can see from my original loop, I used sed to format $var_value to remove the quotations...which seems a little odd to have to do in the first place.
It is odd. Why do it?
Quote:
So perhaps I don't fully understand how declare is working?
What do you think it does?
Quote:
Is this simply a limitation that I cannot get around?
I don't know of any limitation to declare. It does what it is supposed to (but I've never had a reason to use it).
What is the format of the config file? Why do you have to change it?
The config file was mostly intended to be used with a vb script. I didn't really want to start maintaining two separate config files, as I actually do use the vb script as well.
The config file holds variables in the form of ...
variable = "value"
Quote:
Originally Posted by cfajohnson
Why are you using declare? It's not necessary.
I'm using declare because if I don't bash will try to use $var_name as a command. Using declare I can create variables by using variables. This way I can just add variables to the config file if needed and I don't need to go back to the script and manually declare each one separately on it's own line.
Quote:
Originally Posted by cfajohnson
It is odd. Why do it?
Because they would throw my script off as the script takes some action based on the contents of the variables. I would have to account for the variable values having quotations around them which they shouldn't have in the first place.
Quote:
Originally Posted by cfajohnson
What do you think it does?
Well, running 'help declare' at the shell gives me ...
Quote:
declare: declare [-afFirtx] [-p] [name[=value] ...]
Declare variables and/or give them attributes. If no NAMEs are
given, then display the values of variables instead. The -p option
will display the attributes and values of each NAME.
I assumed (yeah,yeah...bad idea to make assumptions ) that it would be like declaring a variable normally only with this the declaration is explicit and you can define its type (dunno exactly what practical use that would give?).
However, after I wrote this I wrote a test that simply does...
So I'm guessing the issue ultimately lies in the way I'm getting the variable values, which seems to allude to a pipeline "issue" (not really an issue, just the way bash handles it) that I read in this thread.
However, I just got around my problem by doing the following ...
So all in all, it works now. It's a bit of a kluge, but oh well.
If I am running a bash command, and some awk getting the ethernet adapter on the local machine. It works fine. But if I will run it from the remote, it is EMPTY on echo and throwing error in grep.
Thank you
This work perfectly fine
$ f=`/sbin/ip a|grep 127.127 | awk '{print $NF }' ` ; ip... (2 Replies)
Hi,
In the code "for loop" has been used to search for files (command line arguments) in directories and then produce the result to the standard output. However, I want when no files are named on the command line, it should read a list of files from standard input and it should use the command... (7 Replies)
This is a short program I wrote to search through a directory and move files containing the keyword to a folder.
#!/bin/bash
echo 'What is the directory?'
read DIR
echo -e '\n'
echo 'What is the keyword?'
read KEY
echo -e '\n'
cd $DIR
rmdir 'relevant_files'
mkdir 'relevant_files'... (5 Replies)
Hello,
I have a script that runs a series of commands. Halfway through the script, I want it to check whether everything is going alright: if it is, to proceed with the script, if it isn't to repeat the last step until it gets it right.
My code so far looks like this, simplified a bit:
... (3 Replies)
Hello all,
I am trying to "make" a database system, VDB (Veritas Data Base), and when I run "make" I receive the following error:
VDBException.h:19: error: expected `)' before '*' token
VDBException.h:20: error: expected `)' before '*' token
VDBException.h:43: error: expected `)' before '*'... (4 Replies)
Hi all
Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends.
As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Hi,
I use AIX (ksh) and Linux (bash) servers. I'm trying to do scripts to will run in both ksh and bash, and most of the time it works. But this time I don't get it in bash (I'm more familar in ksh).
The goal of my script if to read a "config file" (like "ini" file), and make various report.... (2 Replies)
Dear all
I declare like this in my program :
int main(int argc ,char **argv)
{
FILE *ft;
char* ini_file;
char fbuf;
char sendbuf;
char strbuf;
}
When I compile
this is the error :
cc: "send.c", line 28: error 1588: "ft" undefined. (1 Reply)
using bash Tru64...
converting DCL to shell...
any tips to make this work would be greatly appreciated.
Below is my failed attempt to assign command line input to variables by first declaring an array. I use a counter to create unique variables in a loop through the array. I need to call... (3 Replies)