Skip to content

Instantly share code, notes, and snippets.

@tarrsalah
Last active August 2, 2017 23:34
Show Gist options
  • Save tarrsalah/79c5826e862c891a8f065fe6f2d48507 to your computer and use it in GitHub Desktop.
Save tarrsalah/79c5826e862c891a8f065fe6f2d48507 to your computer and use it in GitHub Desktop.
Execute a function with arguments from the commande-line
#!/usr/bin/octave --silent
a = str2num(argv(){1});
b = str2num(argv(){2});
printf("%d\n", a + b);
#!/usr/bin/octave --silent
a = str2num(argv(){1});
b = str2num(argv(){2});
function result = add (a, b)
result = a + b;
endfunction
printf("%d\n", add(a , b));
@tarrsalah
Copy link
Author

I run the script by ./add_example.m 23 43, the result is 66 as expected.
Make sure that the file add_example.m is executable by calling chmod +x ./add_example.m.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment