Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a shell script using Spotlight passing a parameter?

It was mentioned that we can execute a shell script using spotlight renaming it as "myscript.command" as described here. But is it possible to pass a parameter to the script when calling it from Spotlight?

For example:

Script myscript.command:

#!/bin/bash
echo "Parameter: $1"

On Spotlight:

myscript.command test

Output:

(...)
Parameter: test
(...)
[Process completed]
like image 975
Arthur Accioly Avatar asked Feb 29 '16 23:02

Arthur Accioly


People also ask

How do you pass a parameter to a shell script?

Using arguments Inside the script, we can use the $ symbol followed by the integer to access the arguments passed. For example, $1 , $2 , and so on. The $0 will contain the script name.

How do you pass variables in a script?

Arguments can be passed to the script when it is executed, by writing them as a space-delimited list following the script file name. Inside the script, the $1 variable references the first argument in the command line, $2 the second argument and so forth. The variable $0 references to the current script.

How do you pass a variable in UNIX?

In a shell script, you can pass variables as arguments by entering arguments after the script name, for example ./script.sh arg1 arg2 . The shell automatically assigns each argument name to a variable. Arguments are set of characters between spaces added after the script.

What is a parameter bash?

In Bash, entities that store values are known as parameters. Their values can be strings or arrays with regular syntax, or they can be integers or associative arrays when special attributes are set with the declare built-in. There are three types of parameters: positional parameters, special parameters, and variables.

How do I run a shell script from spotlight?

Save your shell script with a .command suffix - this makes it double-clickable and you should also be able to run it directly from Spotlight too. Show activity on this post.

How to pass parameters to a function in shell script?

In shell script functions, you can directly pass parameters during function call, without defining their names in your function definition, and directly refer to them using positional parameters $1 for first argument, $2 for second argument and so on. Let us look at it with an example. There are two ways to define functions in shell script.

What are the special parameters in the Bash shell?

The variables are the parameters that are defined by the user to use in that specific shell script. And the Special parameters are the read-only variables that are predefined and maintained by the shell. Now let’s see what are the Special parameters in the bash shell. This parameter represents the number of arguments passed to the shell script.

What are shell spscript parameters?

Introduction to Shell Script Parameters Shell Spscript parameters are the entities that are used to store variables in Shell. Among these parameters, the named spaces are there in the memory and they permit us to access these stored variables. Generally, there are two types of parameters.


1 Answers

No, it does not seem to be possible currently.

like image 101
tripleee Avatar answered Oct 12 '22 23:10

tripleee