1

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.

1 Answer 1

1

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)))
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. It really helped me. Can you just suggest any command that automatically takes the present file when i press enter (just like % in .vimrc file. basically i want that interactive command should not invoke automatically when i dont pass any argument as filename while calling the function and automatically takes the present file.

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.