Problem in executing a comand liying inside a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in executing a comand liying inside a variable
# 1  
Old 08-09-2006
Question Problem in executing a comand liying inside a variable

Hi everyone!

I need some help with my shell script Smilie

I am sending a shell command from a html text input to a cgi. Then, I store it into a variable. For example

var="ps -axu"
echo `$var`

This functions properly. But consider the following...

var="ps -axu | grep root"

Now, I want to execute this command but if I do this:

echo `$var`

it produces an error.

Why when I add pipes into my string it does not work?

Thank you a lot Smilie
# 2  
Old 08-09-2006
If you really want to do it this way, you need to eval the command.
Code:
var="eval ps -axu | grep root"
echo `$var`

but really, what are you trying to accomplish?
# 3  
Old 08-09-2006
It works! Smilie

I need to execute an arbitrary command introduced by the user in an html form and print the result. It's for a university subject.

Thank you!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Executing statements inside forloop parallely

Hi All, I have made a forloop as given below. if ]; then echo -e "serv_AAA_DS.ldif file created and will be splitted into 8 smaller files for ldapadd \n" sh ./file_splitter.sh for (( w=1; w <= 8; ++w )) do nohup ldapadd -x -c -h PL0 -p 389 -D "$LDAP_USER" -w... (8 Replies)
Discussion started by: Kamesh G
8 Replies

2. Shell Programming and Scripting

Problem using variable inside awk

HI, This is the code I am using: awk -v aaa="connect" 'BEGIN {IGNORECASE} /aaa/,/!/ {print NR}' bb This does not throw any error but it does not work. Pls help Thanks. (4 Replies)
Discussion started by: sudvishw
4 Replies

3. Shell Programming and Scripting

Passing variable as an input file to AWK comand

Hi, I would like to compare 2 files using awk, which I can do by using: awk 'NR==FNR{a;next} (NR > 32 && $2 in a) {print $0}' File1 and File2. If the name of the File1 is in another file (for example, column 4 in File 3) then how can I pass this column 4 to the awk command. Thanks in... (1 Reply)
Discussion started by: ezhil01
1 Replies

4. Shell Programming and Scripting

Preserve extented ascii character when run echo comand inside bash script

Hi everyone, I'm echo some text with extended ascii characters as below: echo -e "Pr\xE9sentation du spectacle" > output or echo -e "Présentation du spectacle" > outputIf I open the file created I see this text Présentation du spectacleThe text is shown correctly in this created file when... (7 Replies)
Discussion started by: Ophiuchus
7 Replies

5. Shell Programming and Scripting

problem in assigning substr to a variable inside awk

Hi All, I have a fixed-width datafile from which i need to extract value/string starting from some position to the specified length in each of the lines. awk '{print substr($0,x,y)}' datafile --- is working fine but awk 'BEGIN{a=0}{a=substr($0,x,y);print $a}' datafile ---is giving... (3 Replies)
Discussion started by: loggedin.ksh
3 Replies

6. Shell Programming and Scripting

Executing 'find' with variable as pattern problem

Hello everybody! Here is my problem: I try to write a script that searches for files with several extensions using the find utility. The file extensions are defined in a list so I build a string (variable) of the pattern arguments with these extensions but can't get find working. Here is a code... (3 Replies)
Discussion started by: Ro_land
3 Replies

7. UNIX for Dummies Questions & Answers

Problem with executing command inside a cron job

Hi All, I have scheduled a script in cron which writes output to the below file. ....>> /data/Target/wrapper_invoke_ds_job_`date '+%Y%m%d'`.ksh_out 2>&1 But the date command is not getting resolved in the format specified. It just resolves to the following. wrapper_invoke_MQ_ds_job_Tue... (3 Replies)
Discussion started by: pkm_oec
3 Replies

8. Shell Programming and Scripting

variable inside variable inside loop headache

Hi Gurus I have a file called /tmp/CMDB which looks like this serial: 0623AN1208 hostname: server1 model: x4100 assetID: 1234 I am writing a for loop that will go through this file line by line creating a variable of itself. Using the first iteration of the loop (i.e. the first line) as... (6 Replies)
Discussion started by: hcclnoodles
6 Replies

9. Shell Programming and Scripting

executing 2 or more files inside another file parallely

hi All, i have 3 files file1 file2 file3 these 3 files are shell (KSH) scripts. i want to place all these 3 shell scripts in another file file99 and execute these files simultaneoulsy inside the file99 these 3 files should be present and executed simultaneously when i excute file99 (nohup... (1 Reply)
Discussion started by: dareman123
1 Replies

10. Shell Programming and Scripting

problem with Variable inside SSH

Hi Friends, i have small issue,... here is my problem............:) i am using two unix box A and B ..using my script i am able to connect from A to B without password(using ssh option like below). A:-> ssh user@B-2.10.32.23 but i declared one variable in A which is something... (5 Replies)
Discussion started by: Shahul
5 Replies
Login or Register to Ask a Question