C
C
Coixe_1p2019-06-30 17:00:48
linux
Coixe_1p, 2019-06-30 17:00:48

Why is the script throwing an error?

I need to write a simple script that will give me the contents of a specified directory.

#!/bin/bash

echo -n "Enter a folder name: "
read way 

ls $way

On execution it gives an error:
ls: cannot access 'path specified': No such file or directory
Given that the specified path exists, and when the command is executed in the terminal, everything is displayed.
Find gives a similar error.
What did I do wrong? Read reads the input, assigns it to the $way variable, that is, the result is ls 'my path', what else does it need?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ronald McDonald, 2019-06-30
@Coixe_1p

Given that the specified path exists, and when the command is executed in the terminal, everything is displayed.

How do you enter the directory path?

S
Saboteur, 2019-07-01
@saboteur_kiev

#!/bin/bash

echo -n "Enter a folder name: "
read way 

eval "ls $way"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question