Use the print result of a script as an argument


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use the print result of a script as an argument
# 1  
Old 02-13-2012
Question Use the print result of a script as an argument

Hi all,

Say I have a script named script.sh. What it does is to print a line like "abc"
Code:
#! /usr/bin/ksh
 
print "abc"

I would like to pass this value to an external variable,

var1="script.sh"

However when I echo $var1 I got "script.sh" itself instead of the result?

Thanks
# 2  
Old 02-13-2012
use this one.
Quote:
var1=`./script.sh`
# 3  
Old 02-13-2012
Code:
$ echo 'echo "hello world"' > a.sh
$ chmod 755 a.sh 
$ var=$(a.sh)
$ echo $var
hello world

# 4  
Old 02-13-2012
Code:
var1=`ksh script.sh`

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To get or print specific value in result

i am executing below code to achive my result, but for second row the value is not coming it should come URL like other two . url start with http:// and end with .xhtml cat FILE | grep 'Test failed' | awk -F',' '{print $3,$8,$12}' INPUT 1517679173303,84,SKILLED LANGUAGE - ENTER... (11 Replies)
Discussion started by: mirwasim
11 Replies

2. UNIX for Dummies Questions & Answers

Print result of mv -n

I am trying to move files which donot have same filename using find /Users/ParijatMac/desktop/unix/new_dir -type f -mmin +"$HRS" -exec mv -n "{}" /Users/ParijatMac/desktop/unix/old_dir \; -print but i am getting all filenames including the ones with duplicate names.Please help me to sort... (5 Replies)
Discussion started by: parijat guh
5 Replies

3. Shell Programming and Scripting

Print if found non-desired result

I have a result like this root@server # grep -rl maldet /etc/cron* /etc/cron.d/maldet_daily /etc/cron.d/malcron /etc/cron.d/malcrondaily /etc/cron.d/malcronweekly What I need is, I need an if/else condition such that, if there is any output other than /etc/cron.d/maldet_daily in the... (8 Replies)
Discussion started by: anil510
8 Replies

4. Shell Programming and Scripting

Find a group of result and print last hits

Hi I would like to search some data with awk and then print the last of the hits. Find house and print last value input:red house 4 blue boat 2 green house 6 black car 7 output:6 I now how to search using /house/, print third field print $3, an now I may use some form of $NR to get the... (3 Replies)
Discussion started by: Jotne
3 Replies

5. UNIX for Dummies Questions & Answers

How to print number before argument?

Hey everyone, I need to write a script that will display the number of the argument before displaying the argument itself. Here's what I have so far: for arg in "$@" do echo $#:$arg done This returns the sum of all arguments preceding the arguments themselves. $(script) a b c 3:a... (1 Reply)
Discussion started by: unclepickle1
1 Replies

6. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

7. Shell Programming and Scripting

how to print all argument passed

like i have script with which i have passed arg list :eg: i/p: scriopt1 arg1 arg2 arg3 .... argn o/p: arg1 arg2 arg3 .... argn (2 Replies)
Discussion started by: RahulJoshi
2 Replies

8. Shell Programming and Scripting

print out result from data file

i got a data file which contains all the pid,ppid,user,command,pcpu,start_time,status. I wanted to display out the pcpu which is greater than 0. i uses awk'{if($5 > 0){print}}' filename.txt but is printing out result which not i wanted. Is there any way which i can print out those pcpu which is... (8 Replies)
Discussion started by: thms_sum
8 Replies

9. Shell Programming and Scripting

print a function result in new file

Hi, i have a function which return a variable . serach ( paramatere) when i excute this function i get the result in the shell, i want to print this result in a file by calling just the function. how can i do it.. the code example is like that: search ( ) { .. } the call... (0 Replies)
Discussion started by: kamel.seg
0 Replies
Login or Register to Ask a Question