0

Hello guys so I was trying to create a script that lists all files in the current directory, the parent of the working directory, and the /boot directory here is what I tried

#!/bin/bash
ls -la ls -la ../ ls -la /boot

I have already made the file executable. The problem comes in when I run it. The error states;

ls: cannot access 'ls': No such file or directory

What could I be doing wrong?

1
  • You'd have the same thing running this on a regular command line; it's not a script-specific issue (and thus not a programming-specific issue either). Commented Oct 5, 2022 at 16:22

1 Answer 1

2

The problem is that ls -la ls tells the ls command to look for a file or directory named ls, which doesn't exist.

If you want multiple commands on one line, they must be separated with a semicolon (;).

ls -la; ls -la ../; ls -la /boot

If you split the commands onto multiple lines, the semicolon becomes optional:

ls -la
ls -la ../
ls -la /boot

Or you can just pass multiple directories to ls like so:

ls -la . ../ /boot
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.