• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

store the output of "find" command in a variable?

 
shield kumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to store the output of "find" command in a variable inside a shell script?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11893
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try:

The variable $FILES will now contain a list of all the files, directories, links ... in your home directory and sub-directories.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18226
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's also an alternative notation that's common:

FILES=`find . name "*.pdf"`

Note that the delimiter for the command string is the "backtick" character, sometimes known as "left apostrophe". It's not the same thing as the normal (right) aprostrophe. On many keyboards, it's located to the left of the "1" key. In my case, it's on the same key as "~".
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:Note that the delimiter for the command string is the "backtick" character, sometimes known as "left apostrophe". It's not the same thing as the normal (right) aprostrophe.

That's one reason why it's deprecated: confused by beginners.

The second reason is, is, it is hard to nest Commands with backticks, but easy with brackets.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic