1827967 Members
2373 Online
109973 Solutions
New Discussion

Re: Script help

 
Venkat_33
Frequent Advisor

Script help

Hi,

I want output of both like

testin='ls -a'

output with that command how do that
13 REPLIES 13
RAC_1
Honored Contributor

Re: Script help

I am not clear as to what exactly you want.

alias testin='ls -a'

testin would now give what 'ls -a' would give.
There is no substitute to HARDWORK
Venkat_33
Frequent Advisor

Re: Script help

my script will do

testin=`ls -a`

echo $testin >> out.txt

and also i want to include that ls -a command to that file.
RAC_1
Honored Contributor

Re: Script help

type testin >> some_file
Also, you do not need to do echo $testin >> some_file, you need to do as follows.

testin >> some_file
There is no substitute to HARDWORK
Venkat_33
Frequent Advisor

Re: Script help

hi RAC,

its not working
RAC_1
Honored Contributor

Re: Script help

what is not working??
There is no substitute to HARDWORK
Venkat_33
Frequent Advisor

Re: Script help

what is my question is

i want to output the 'ls -a' to some file and also will include what command i executed for this output eg:'la -a'
RAC_1
Honored Contributor

Re: Script help

type testin >> some_file;testin >> some_file
There is no substitute to HARDWORK
James R. Ferguson
Acclaimed Contributor

Re: Script help

Hi Venkat:

Perhaps this is what you want (by example):

# CMD="ls -l /var/tmp";{ echo executing: $CMD;$CMD; } > file

Regards!

...JRF...
Howard Marshall
Regular Advisor

Re: Script help

Just to break it down to its most simple form, If I understand what you want

echo â output from ls â a commandâ > file.out
testin=$(ls â a)

echo $testin >> file.out


in this case $( ) works just like the back tick ` `


Howard
Howard Marshall
Regular Advisor

Re: Script help

ok, lets try that again


echo "output from ls -a command" > file.out
testin=$(ls -a)

echo $testin >> file.out


see if that prints better
stupid Word

Howard
Sandman!
Honored Contributor

Re: Script help

Venkat,

If you want to capture the output of the command as well as the executed command then "script" might be what you're looking for...man script(1)

cheers!
rmueller58
Valued Contributor

Re: Script help

I would to this

export testit=`ls -a`

Tom Danzig
Honored Contributor

Re: Script help

" want to output the 'ls -a' to some file and also will include what command i executed for this output eg:'la -a' "

CMD="ls -a"
echo "$CMD" > /tmp/file
$CMD >> /tmp/file

This answers your question but is not very elegant. Setting a variable to the output of a command as you posted originally is not a good idea. It would work provided you put double quotes aruond the grave accented command provided there are not too many files present.

Suggest you just do:

ls -a > /tmp/file

and be done with it.