Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


$ getfacl somefile.dat     # The output is formatted and contains several new lines..

# file: somefile.dat
# owner: user1
# group: group1
group::r--              #effective:r--
$ ACL_PERMISSIONS=$(getfacl somefile.dat);
# file: somefile.dat # owner: user1 # group: group1 user::rw- group::r-- #effective:r-- mask:r-- other:r--

So how do I preserve these new lines during variable assignment, so that when I echo $ACL_PERMISSIONS I get the same output as $ getfacl somefile.dat ..?

share|improve this question
Kindly explain the reason for the -1..? – Kent Pawar Apr 17 '13 at 8:42
I'm not the downvoter, but my guess would be that it is because this is an issue merely involving missing quotes (which I don't think warrants a downvote, but I've seen it happen before on questions like this). – Chris Down Apr 17 '13 at 8:44
up vote 4 down vote accepted

You need to quote your expansion, otherwise it will undergo word splitting, which is what you are experiencing.

acl=$(getfacl somefile.dat)
echo "$acl"

Bear in mind that $( strips trailing newlines anyway (it is considered a feature). If that is a problem for you, you need to do something like this to preserve them (in bash4+):

mapfile acl < <(getfacl somefile.dat)
printf %s "${acl[@]}"
share|improve this answer
Hey @Chris, Thanks! I wasn't aware of 'word splitting' and using quotes around the variable does solve my problem.. Just curious, how can I preserve trailing newlines (not sure where such a thing might help) using ksh..? – Kent Pawar Apr 17 '13 at 8:49
@KentPawar The first method should also work in ksh. – Chris Down Apr 17 '13 at 8:55
Yup, it does.. Sorry, but didn't quite get your 2nd example.. whats mapfile doing..? – Kent Pawar Apr 17 '13 at 8:58
@KentPawar From help mapfile: "[r]ead lines from the standard input into an indexed array variable". It essentially reads each line from the output of getfacl somefile.dat into an array called acl. – Chris Down Apr 17 '13 at 9:00
@Kent - sorry for confusion. "strips newlines" is not a command it is just text. I think in your case you just need to enclose the variable in quotes as Chris suggested. – suspectus Apr 17 '13 at 10:08

Your Answer


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.