1

I'm a basic user hoping to advance to an intermediate level. Ok, I've a file XAMPP(manager-linux-x64.run) which when i do a

sudo ./manager-linux-x64.run

It works. So, I was trying to go pro by doing this from its directory

ls | grep manager-linux-x64.run | sudo xargs ./

it doesnt work.it throws this error

xargs: ./: Permission denied

The file output of manager-linux-x64.run is

manager-linux-x64.run: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, stripped

What I am essentially trying to do is get a list of files in the directory , grep the executable, pipe the output and execute it using ./manager-linux-x64.run since (sh,bash doesn't work on the .run file).

Moreover, is there any other command that can run a .run itself?

Zanna
  • 70,465
Emma
  • 21
  • You might find this useful. – Elder Geek Feb 22 '17 at 16:03
  • 1
    If it works by issuing sudo ./manager-linux-x64.run, I don't really get what you are trying to do. For what purpose were you "trying to go pro by doing this from its directory"? What do you really mean to accomplish? – Samuel Feb 22 '17 at 16:43
  • xargs pass its input as arguments to another command, you are lacking that other command. – Samuel Feb 22 '17 at 16:51
  • actually, you are telling xargs to (try to) execute command ./ with the results of your ls . . . | grep as arguments – steeldriver Feb 22 '17 at 17:03
  • I still don't get why you're trying to do this. – muru Feb 23 '17 at 01:49
  • muru, I'm only trying to learn how to find and execute a file which is not necessarily a .sh file. Thanks – Emma Feb 23 '17 at 06:08
  • @Emma why use xargs at all? I agree I don't see the point of your method. Why not execute it directly? – Sam Gleske Feb 23 '17 at 08:48
  • @Sam Gleske, i get it that i can execute directly, if i have say 50 or 100 types of file like this .run file(just saying) ..would you suggest i execute it all manually? – Emma Feb 23 '17 at 13:25
  • @Emma yes, even if you had 50-100 file of the same type I would say execute them directly. If by directly you mean referencing the script. In general, I've not encountered a use case like you mention. There are other cases where I'm using different file types and am using a for loop or find command to iterate across them. – Sam Gleske Feb 24 '17 at 07:12

1 Answers1

3

The answer is a subshell. Try this:

realpath $(ls) | grep .run$ | xargs sh -c

Or:

ls -d ./* | grep .run$ | xargs sh -c

Those will work, but it might be better to use find if what you are trying to do is execute a file whenever it fulfills certain conditions.

find $PWD -maxdepth 1 -type f -name "*.run" -exec {} \;


Notes:

The file's executable permission must be set. Change with chmod if needed.

A warning: the previous one-liners will try to execute anything they match. Read about dot slash:

"...A user could eliminate the need to precede commands by a dot slash (...) However, this is generally not advisable on safety and security grounds..."

Samuel
  • 1,015