Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The result of the following script:

results=$(find -iname "*.mp4")
echo $results;

is something like:

file1 file2 file3

How do I pass the results of the find command to a variable, as it is shown when I run the following command in terminal:

find -iname "*.mp4"

which prints:

file1
file2
file3
share|improve this question
    
How do you want to use this result? –  Mat Nov 3 '12 at 7:48
    
@Mat I want to pass the results to zenity --text-info –  Omid Nov 3 '12 at 7:51
add comment

2 Answers 2

up vote 3 down vote accepted

Instead of doing echo $results do echo "$results".

Update:

The difference between the 2 is that in the 1st case echo receives many parameters and in the 2nd case it receives only one parameter. This is because variable substitution occurs before parameter parsing.

share|improve this answer
add comment

Try this, an example on zenity lists, it read the result from find, and generate an array, then pass on to zenity:

#!/bin/bash

List=()
while IFS= read -d $'\0' -r file ; do
    List=("${List[@]}" "$file")
done < <(find . -iname '*.mp4' -print0)

zenity --list --column "Item" "${List[@]}"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.