General :: Bash: Substitute Parameter In A Quoted String - Stored In Another Variable
Jan 31, 2010
(variable substitution?)
(parameter expansion?)
Code:
run_repeatedly()
{
NUM=0
while [ <irrelevant stuff here> ]
[Code]....
run_repeatedly "programX -o "./messy/path/output-$NUM.txt"" The echo inside the loop prints "...-$NUM.txt"; obviously I'm aiming to have bash substitute the iteration number so that I end up with many output files not 1.
View 5 Replies
ADVERTISEMENT
Mar 21, 2011
Assume that i a having the following three lines in an executable file
#/bin/bash
a=Tue
Tue=1
When i give echo $a the value should be 1, how to do this.
View 8 Replies
View Related
May 10, 2011
I want to create a variable that when passed as a parameter to another bash script will keep its string quotes (so it stays as one parameter). What ways can I achieve this cleanly?
Code:
john@ubuntu:/usr/local/src$ cat foo.sh
#!/bin/bash
echo $0
[code]....
View 8 Replies
View Related
Feb 9, 2011
I do this:
Code:
a@b:~$ export A=hi
a@b:~$ echo $A
hi
a@b:~$ bash -c "export A=blah; echo $A"
hi
a@b:~$
Why doesn't the bash command print the new value of $A? Is there a way to make it do so?
View 6 Replies
View Related
Aug 6, 2011
I have a file (.tmpfile) and inside it is a string which i only know part of, the rest being a random group of characters... I would like to know how to pull the whole string out of the file and into a variable.
View 13 Replies
View Related
Feb 19, 2010
I am having some weird problems with calling commands stored in a variable (I need to do this to assemble a command with a bunch of parameters automatically and then execute it).Example code that will replicate the weirdness:
$ echo "hello world" > "test file.txt"
$ cat "test file.txt"
hello world
[code]....
I would expect the output to be:
hello world
What happens to the quotes? I have tried various combinations of single quotes, escaped quotes, etc, but it seems like quotes in a variable are not evaluated as quotes when that variable is executed.
View 9 Replies
View Related
Jan 18, 2011
I have a program that loops over each word in a sentence. I need to append a constant to the beginning and end of each word. It works up until the last word on the line.
Code:
Output:
View 4 Replies
View Related
Jan 24, 2010
Here is the code:
Code:
How ever when I run this script I get the following error
Quote:
I just don't get it, I have racked my brain trying to figure out every combination of how I should write this if statement and I can't get it to work.
View 2 Replies
View Related
Jul 7, 2011
Bash 3.1.7
Code:
Code:
Code:
I think read A1 A2 makes A1, A2 string variables. Then, when A2 gets the value 01, '01' should be a string. But for some reason bash takes it as numeric. I know there are no types in bash.
View 11 Replies
View Related
Sep 24, 2010
Iḿ trying to install TCL 8.0.5 onto my machine, if i type �wish it tells me there are already these programs:
Code:
The program 'wish' can be found in the following packages:
* tk
* tk8.4
* tk8.5
* tk8.3
Try: sudo apt-get install <selected package>
The error trace is here:
Code:
luke@luke-laptop:~/Downloads/tcl8.0.5/unix$ ./configure
loading cache ./config.cache
checking for ranlib... ranlib
checking whether cross-compiling... no
checking for getcwd... yes
checking for opendir... yes
code....
checking system version (for dynamic loading)... ./configure: 1: Syntax error: Unterminated quoted string
Really not sure whats wrong, I�m horrible with linux if I�m honest, tried a couple of google searches but didn�t make very much progress.
View 2 Replies
View Related
Mar 26, 2011
For example, when using bash you can use
Code:
to execute the previous command or
Code:
!<number> to execute the Nth command(use history to see the list). Or you can use
Code:
cd !-2:1
to cd into the value in the first field that was executed 2 commands ago Anyhow, say I run a command and the output is a path. Any way to cd and then some variable where OUTPUT of the previous command was stored? A variable that always stores the OUTPUT of the last command.
View 8 Replies
View Related
Dec 8, 2009
On one of my servers I see this when I log in. What does this mean and how can I get it to go away? Everything seems to work fine, but none of my other machines give this error.
View 5 Replies
View Related
Apr 7, 2010
my script has a variable which comes in the form +00.00 +0.00 -00.00 or -0.00 (the numbers can be any in that form) for any that have a + symbol I need to remove the +, but if it has a - symbol it needs to stay.
i need to make a new variable with the string from the old variable btut without any plus sign. I have tried a lot of different ways with no success, each thing I tried either left the + or removed the entire string. I think this should work but doesn't
foo=+12.40
bar=${foo#+}
View 4 Replies
View Related
Jul 13, 2010
I'm facing problems in developing the script as there are errors that sometimes i dun have any idea on how to solve it.What i'm doing now is not homework, but i had been assigned to develop some system in linux.
My problem currently is on sub-string matter, where i need to read the line from file/directory and based on the line retrieved,i need to seperate the information in the line and assign as variable..
Below are my script:
Thus, the output something like this: file_name successfully ran on Mon Jul 12 23:15:00 SST 2009.
Now, what i need to do is to extract certain information from that line which is the name, date, time and the status
The desired output is:
So,my next step is to identify the sub-string and assigned as variable first in order to parse the info and output it.
Thus,my script is:
But i received error message which is:
View 14 Replies
View Related
Nov 15, 2010
How do i convert variable to string?
For example:
So how do i make the code with variable work?
View 7 Replies
View Related
Jul 31, 2010
Code:
a=/this/is/a/dir.txt
dirname $a
[code]....
View 2 Replies
View Related
Apr 11, 2011
I want to match some filename in some text, but the filenames I have no control of, so "[" can "]" can appear in the filenames.so do I always have to use sed to addslashes to these variables before I have to grep them? and what other characters have I missed other than "[", "]", "."?
View 4 Replies
View Related
Jan 21, 2011
Say, i have an imaginary std library function, which I want to call.
Code:
void std_lib_func(ObjectType *param);
Now in my c++ program, I have a main() function, and I will like to call a customized function (which will in turn call the std lib function) from the main function, as below:
Code:
int main()
{
ObjectType *aobj;
customized_func(aobj);
}
[Code]...
I tried the below but get an error that the std lib function is expecting a ObjectType* param, not aobj. How should I work this out.
Code:
void customized_func(ObjectType aobj)
View 4 Replies
View Related
Mar 8, 2011
I am trying to give a parameter or string by default to the prompt after booting from CD/DVD after modifying isolinux.cfg file For this I am able to successfully alter the boot.iso present in RHEL+CENTOS DVDs using the below command mkisofs -o /new.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -R -V disks . But, when I am trying to alter the Netbackup BMR iso file it does not has boot.cat file and also giving me below errors.
[Code]...
View 2 Replies
View Related
Jan 12, 2009
I need to call a function that takes a string array as argument, declared like this:Code:int someFunction(/* some parameters... */, const char* s[]);I'd like to know how to allocate memory for the string array. I know a string is an array of chars and an array is a pointer to the first element, then a string array should simply be a two dimensional char array. But is it a single memory block where all strings are stored consecutively?? Or is it a base vector where each element is a pointer to a separate memory block that contains a single string?More specifically: should I malloc() a single memory block large enough for all the strings? or should I allocate separate blocks for each string plus an extra one for the base vector?
View 5 Replies
View Related
Jan 19, 2010
I need to search a text file for a string of numbers which are different lengths, and always are between number=" and " like:
number="1234567890"
number="22390"
I need to grab those numbers and pipe each one to a line in a file. I've already tried something with awk and that didn't seem to work.
View 10 Replies
View Related
May 4, 2010
I got the following modprobe scripts modprobe -k -q streams what does the -k parameter mean?. is it exist in older modprobe? I don't see -k parameter in recent modprobe.
View 1 Replies
View Related
Aug 21, 2009
I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.
For example:
Code:
Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).
View 6 Replies
View Related
Jun 10, 2009
I have a text file i that has a mailTo: NAME in it. In a bash script i need to extract NAME and put it in a $variable to use. How do i do this?
View 2 Replies
View Related
Mar 10, 2011
I've a string "this.is.a.name", and I would like to return "is.a.name". How can I do that in bash?
View 3 Replies
View Related
Mar 21, 2011
I've a script that it's invoked with n-variable parameters. Here's an examples:
Code:
./myprogram.sh inputdir FIELD1 FIELD2 ... FIELDN outputfile In the script I would like to get the FIELD names that were passed.
View 4 Replies
View Related
Nov 8, 2009
I have to create a bash script that takes an arbitrary length number from the command line, and add up each individual digit
Ex:
server> myscript.sh 123
server> 1 + 2 + 3 = 6
The problem I'm having is pulling out each character.
Is there a way in bash I can parse the input string for each character? I can't figure out a way to do this.
View 4 Replies
View Related
Mar 20, 2011
I would like to return the last part of a string in an array of strings in bash.
The array contains in each position the content below:
Code:
a.b.c
a.d.f
a
a.d
[Code].....
View 5 Replies
View Related
Mar 17, 2011
how do I split a string into an array?In this string:"this is a story"how do I split it by the space?
View 8 Replies
View Related
Aug 22, 2010
I'm basically setting up two sshfs mounts and I have it set up so I run one command but type my password twice.Is there an easy to way to input a password using bash and pass that variable to another process asking for a password?
View 5 Replies
View Related