Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I'm having issues in running this bash script

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading