Use the execute
command. Everything after it is an expression that evaluates to a string, which it then executes like a command you had typed in yourself.
function Ls(dir)
execute '!ls ' . a:dir
endfunction
This says, “Evaluate the expression '!ls ' . a:dir
and then execute it.” The variable a:dir
is expanded, the dot concatenates the two strings into '!ls whatever'
and then that is executed as if you had typed it.