Skip to content

How to read a file into a variable preserving newline #108

@edwinjhlee

Description

@edwinjhlee

Fail using command substitution

cat >a.txt <<A
a
b
c
A
set data="`cat a.txt`"
cat -n <<A
$data
A

# The output is 
#  1	a b c

setenv data "`cat a.txt`"
cat -n <<A
$data
A

I read the mac document, it seemed csh just turn it into a word list during command substitution. I have tried using unset csubstnonl. It doesn't work.

My questions is, is there another way in csh that I can read the file and save the content to a variable preserving newline ?

My csh version is :

tcsh 6.24.10 (Astron) 2023-04-14 (aarch64-apple-darwin) options wide,nls,dl,al,kan,sm,rh,color,filec

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions