Passing string as variable(s) in bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing string as variable(s) in bash
# 1  
Old 04-06-2013
Passing string as variable(s) in bash

I'm trying to write a basic bash script that takes input you give (what directory, if any, what name, if any ....) and passes the information to find.

I'm trying to just create a string with all variables and then pass it to find. So far I have this extremely simple:

Code:
#!/bin/bash -f

test_str="-name bin"
find `$test_str`

I'm trying to make it the same as
Code:
find -name bin

Could someone give me an idea on how to achieve that?
# 2  
Old 04-06-2013
No backticks!
Code:
find $test_str

In case you mean "passing arguments to the script":
Code:
find $1 $2 $3

Code:
find "$@"

This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 04-06-2013
Haha, thanks a lot! No backticks worked like a charm. I'm extremely new to writing scripts - as you can probably tell.

It was so obvious yet I complicated it unnecessarily. Once again, thanks. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Passing variable from PHP to bash script

I am totally new to PHP and I am trying to create a script that will as a user for a hostname and then use the "hostname" variable to generate a report using REST API. I am able to create the html script and php script to GET the "hostname" but I am having trouble passing the hostname variable... (10 Replies)
Discussion started by: kieranfoley
10 Replies

2. Shell Programming and Scripting

Passing string from bash to sqlplus

Hello, I have file (PARFILE) with string on first line: INCLUDE=SCHEMA:"IN\( 'SCHEMA1','SCHEMA2','SCHEMA3' \)"In .sh script I use: .... IMPORT_SCHEMA=`awk 'NR==1{print $2}' ${PARFILE}` ...print $2 is because 'SCHEMA1','SCHEMA2','SCHEMA3' is 2nd column in file echo "$IMPORT_SCHEMA"... (5 Replies)
Discussion started by: DjukaZg
5 Replies

3. Shell Programming and Scripting

Passing variable from bash to perl script

Hi All, I need to pass a variable from bash script to perl script and in the perl script i am using those variables in the sql query but its giving error : Use of uninitialized value $ENV{"COUNTRYCD"} in concatenation (.) or string at /GIS_ROOT/custom/tables/DBread_vendor.pl line 50. Can ... (6 Replies)
Discussion started by: NileshJ
6 Replies

4. Shell Programming and Scripting

Passing string from SQL to a BASH script

OS Solaris 10, DB oracle 10g Hello, We currently have a BASH script that runs and moves image files from a remote server to the local db server. A snippet of the code shows that we are picking up all Images that are 'mtime -1' some code... for file in `ssh user@10.200.200.10 'find... (3 Replies)
Discussion started by: JonP
3 Replies

5. Shell Programming and Scripting

Passing a string variable from Unix to Sql Plus

Hi Guys, I am trying to pass a string variable from Unix shell script to sqlplus as a parameter. I have tried using single quotes with the variable name but it does not work. Please help me with it. I am using BASH. My code: Your help is much appreciated. Thanks, shil (2 Replies)
Discussion started by: infintenumbers
2 Replies

6. Shell Programming and Scripting

Trouble with passing Variable from bash to awk gsub command

Would really appreciate it if someone could point out my mistake in this line of code, i've been staring blankly at it trying everything i can think of some time now and coming up with nothing. #!/bin/bash echo "Enter Username" read Username awk -F: -v var=${Username} '/^var:/... (9 Replies)
Discussion started by: Nostyx
9 Replies

7. Shell Programming and Scripting

Bash assign string to variable

Hi ,I am trying to assign string to variable ,but it doesn't work Also could you show me different ways to use grep,(I am trying to get the first,second and first column form file,and I am counting the chars) let name=`grep "$id" product | cut -c6-20` (25 Replies)
Discussion started by: lio123
25 Replies

8. Shell Programming and Scripting

Passing Bash variable to javascript

How do I pass a bash variable to a javascript? I've tried #!/bin/bash echo "Content-type: text/html" echo "" echo "<html>" echo "<head>" counter=0 echo '<script> window.parent.document.forms.counter.value = "$counter"; </script>' I have an iframe script which I am trying to pass a... (3 Replies)
Discussion started by: numele
3 Replies

9. Shell Programming and Scripting

Bash string variable manipulation

In a bash script I've set a variable that is the directory name of where an executable lives. the_dir=`dirname $which myscript` which equates to something like "/path/to/dir/bin" I need to cut that down to remove the "bin" so I now have "/path/to/dir/". This sounds easy but as a... (2 Replies)
Discussion started by: Witty
2 Replies

10. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies
Login or Register to Ask a Question