K
K
kirusselll2020-12-04 15:50:50
linux
kirusselll, 2020-12-04 15:50:50

How to display the contents of a file with only the echo and ls commands?

The point is this. There is a file called -text.txt- (with - at the beginning and end). Only echo and ls commands are available, how can I output its contents?

PS The file was created by root, the commands are executed by the user

Answer the question

In order to leave comments, you need to log in

5 answer(s)
L
Lesha, 2020-12-04
@hydrugz

$ cat -- -text.txt-
123
$ echo "$(<-text.txt-)"
123

bash 5

S
Saboteur, 2020-12-04
@saboteur_kiev

echo $(<./-text.txt-)

S
Sergey Karbivnichy, 2020-12-04
@hottabxp

echo `<-text.txt-`
The hacker of me is so-so, but it worked:
5fca3466d00ca655003547.png

I
Insolent Muzzle, 2020-12-05
@pluffie

The options above are correct. If you can’t display the contents, then maybe you need to change the file permissions?

chmod 777 -text.txt-
echo $(<./-text.txt-)

If there is only echo and ls (without chmod), then it is impossible (IMHO).
UPD: I forgot that chmod is done from root. Therefore, it does not fit.

S
shurshur, 2020-12-05
@shurshur

The owner of the file is not important, it is the availability of access that matters. If there is no access to read, then that's it, we've arrived.
So the shortest option was indicated here:
echo `<-text.txt-`
But I think the user was worried about the minus in the name, and not the presence of cat, and it’s easy to deal with this:

cat -- -text.txt-
cat ./-text.txt-

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question