Ishu Gupta
Ishu Gupta

Reputation: 55

how to make own shell command with arguments in emacs?

I want to make my own shell command where i have a variable filename in the command. The filename is passed in an interactive function. I don't know how to save the filename passed as an argument to a variable and further use it to append the whole command.

Upvotes: 1

Views: 555

Answers (1)

legoscia
legoscia

Reputation: 41618

To ask for a file name (or any other type of value), use interactive. (interactive "fFile: ") means to ask for an existing file (that's what f stands for), prompting with File:.

Then, to concatenate a number of strings, use the concat function.

So the function would look something like this:

(defun my-cat-file (filename)
  (interactive "fFile: ")
  (shell-command (concat "cat " filename)))

Upvotes: 1

Related Questions