Sponsored Content
Top Forums Shell Programming and Scripting Help using variable in find rule Post 302708967 by Corona688 on Tuesday 2nd of October 2012 12:40:16 PM
Old 10-02-2012
The short answer is, you cannot put quotes in quotes that way directly, the shell won't do that kind of doublethink. You asked for literal quotes, so it gave you literal quotes; making them go away takes an eval, which means big trouble. If someone manages to cram `rm -RF ~/ into your string, eval will execute that!

I'd do this instead:

Code:
set -- "-not" "-name" "*.xom" "-a" "-not" "-name" "*.sh" "-a" "-not" "-name" "*.pl"

find ... "$@"

This lets you do splitting on arguments instead of spaces, preserving your strings literally without having to deal with quotes inside quotes. This avoids the eval, and makes your code much safer.
This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and replace the value in a variable

I have a variable whose value is I="user1:x:1100:1200:ID for user1:/home/user1:/bin/ssh-dummy-shell" I want to replace the last part '/bin/ssh-dummy-shell' with '/bin/true' I tried using sed but it garbled sed 's/\/bin\/ssh-dummy-shell/\/bin\/true' $I Thanks for the help (5 Replies)
Discussion started by: aajmani
5 Replies

2. UNIX for Advanced & Expert Users

Find a environment variable Value !

There is shell script which contains some variables . These variables are used , but they have not declared in the script. I think its a environment variable, so I want to know where these variables are set and given values In .profile or .login..or where to c Please give the full path and... (1 Reply)
Discussion started by: tkbharani
1 Replies

3. UNIX for Advanced & Expert Users

Find a environment variable Value !

There is shell script which contains some variables . These variables are used , but they have declared in the script. I think its a environment variable, so I want to know where these variables are set and given values In .profile or .login..or where to c Please give the full path and file... (3 Replies)
Discussion started by: tkbharani
3 Replies

4. Shell Programming and Scripting

Find whether the variable holds value or not

when i run a select query in database, it will return the objid based on the condtion. If there is no objid tht meets the condition, I will not get any value returned and the variable will hold nothing... so now how to chk tht the variable is blank or not. I tried the below piece of code: if ;... (6 Replies)
Discussion started by: harish409
6 Replies

5. Shell Programming and Scripting

How can we use a variable value in find command

Hi All: I want to write a shell script to store OS current date - 1 day value in a variable. Current Date is: 22042010 and new value is 21042010 I have multiple files having date value in name in ddmmyyyy format for multiple day, so I want to find all the files based on the date... (3 Replies)
Discussion started by: lodhi1978
3 Replies

6. Shell Programming and Scripting

how to find the value of a variable in zsh?

I have a zsh script written by someone else, I am trying to modify it to work on slightly different data -problem is I know nothing about shell scripting. I am trying to muddle through this myself since I need to learn but can someone tell me how to debug a script? ie. I want to display the value... (6 Replies)
Discussion started by: cmp260
6 Replies

7. IP Networking

iptables - most easy way to find rule and remove it?

I have situation where I have rules in iptables with comments. Now... I can for example enter rule like "iptables -A FORWARD -s xxx -j ACCEPT" and delete it with "iptables -D FORWARD -s xxx -j ACCEPT".. but if that rule contain some random comment (-m comment) then ... ? I can find with scripting... (2 Replies)
Discussion started by: darkman_hr
2 Replies

8. Solaris

Jumpstart -- Warning: Could not find matching rule in rules.ok

I just setup a new jumpstart server, and I'm having problems with rules.ok errors. I'm coming up blank after many Google searches, forum searches, etc..... This is the error I receive: Skipped interface e1000g1 Attempting to configure interface e1000g0... Configured interface e1000g0... (0 Replies)
Discussion started by: christr
0 Replies

9. Shell Programming and Scripting

Find string in variable

korn shell, testing if a pattern exist in a string, x is constant, y could be none,all or any combination of the elements of x, x="aa bb cc dd ee ff gg hh ii jj kk ll" y="ff kk" for z in `echo ${x}` do if <any pattern in $y matches any pattern in $x> ] then do something fi... (3 Replies)
Discussion started by: squrcles
3 Replies

10. Shell Programming and Scripting

How to find no of underscores in a variable?

Hi i have a variable var=a_b_c i want command to find no. of underscores in a variable Thank you (7 Replies)
Discussion started by: pracheth
7 Replies
ESCAPESHELLARG(3)							 1							 ESCAPESHELLARG(3)

escapeshellarg - Escape a string to be used as a shell argument

SYNOPSIS
string escapeshellarg (string $arg) DESCRIPTION
escapeshellarg(3) adds single quotes around a string and quotes/escapes any existing single quotes allowing you to pass a string directly to a shell function and having it be treated as a single safe argument. This function should be used to escape individual arguments to shell functions coming from user input. The shell functions include exec(3), system(3) and the backtick operator. On Windows, escapeshellarg(3) instead removes percent signs, replaces double quotes with spaces and adds double quotes around the string. PARAMETERS
o $arg - The argument that will be escaped. RETURN VALUES
The escaped string. EXAMPLES
Example #1 escapeshellarg(3) example <?php system('ls '.escapeshellarg($dir)); ?> SEE ALSO
escapeshellcmd(3), exec(3), popen(3), system(3), backtick operator. PHP Documentation Group ESCAPESHELLARG(3)
All times are GMT -4. The time now is 09:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy