I am trying to escape some text for a shell command, but i am gettig stuck with this error.

Not enough arguments for format string

From what i can tell its trying to interpret the % symbols.

This snippet produce the error when i output the command, but its fine if i pass it to shell-command.

#+BEGIN_SRC emacs-lisp
(setq dc-str-addresses "{{printf \\\"%.30s\\\" .Name}}{{printf\\\"%.22s\\\" .IPAddress }}")
(message (format "test %s" dc-str-addresses))

Where as this one outputs fine, but give me %% when i pass it to shell-command so how can i make this work for both ? can i tell lisp to ignore the % symbols in my string ?

#+BEGIN_SRC emacs-lisp
(setq dc-str-addresses "{{printf \\\"%%.30s\\\" .Name}}{{printf \\\"%%.22s\\\" .IPAddress }}")
(message (format "test %s" dc-str-addresses))

: test {{printf \"%.30s\" .Name}}{{printf \"%.22s\" .IPAddress }}

I am running the command through shell in this manner. (shell-command dc-str-addresses)

  • Can you show you are passing this to shell-command (every combination I've tried just gives me a syntax error)? Thanks! – Matt Innes Nov 3 '16 at 9:22
  • (shell-command dc-str-addresses) Thats all i am doing when you say it produces a syntax error do you mean shell is ? because the above is not valid shell command but it should error and show you the command it was trying to run thats how i can see when there is %% in the result. – Oly Nov 3 '16 at 10:52
  • I can't actually figure out what your question is, but you should probably take a look at C-h f message because you're not using it correctly. – phils Nov 3 '16 at 11:10
  • Thanks, your exactly right if you want to make that an answer I will happily accept it. (message "%s" dc-str-addresses) is exactly what i needed – Oly Nov 3 '16 at 11:49
  • Your question title and your accepted answer, and thus your actual question, are asking different things. (-1) – mihai Dec 11 '19 at 12:17

Instead of:

(message (format "test %s" dc-str-addresses))

You want:

(message "test %s" dc-str-addresses)

message accepts the same arguments as format:

(message FORMAT-STRING &rest ARGS)

The first argument is a format control string, and the rest are data to be formatted under control of the string. See `format' for details.

Note: Use (message "%s" VALUE) to print the value of expressions and variables to avoid accidentally interpreting `%' as format specifiers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.