mohammad reza
mohammad reza

Reputation: 109

how to save output of a function to a variable in bash

I have a function called fslnvols which gives the number of images in a 4D image.

Usage:

fslnvols <input>

I wanted to save the output of the function to variable A,so I tried:

A=fslnvols inputimage

and

fslnvols inputimage

A=$(fslnvols)

but I didn't get the wanted result, any idea how to fix it?

Upvotes: 1

Views: 445

Answers (1)

heemayl
heemayl

Reputation: 42137

Use command substitution, $():

A=$(fslnvols inputimage)

The command whose output you want to store as variable A, goes inside $() -- fslnvols inputimage in this case.

Upvotes: 2

Related Questions