I haven't used shells much |
You were using Bash in a prior thread so I assumed you were more familiar with it. No worries.
Firstly you shouldn't need to write a separate script for each of these commands. Just type them right in. Although again I'm very unfamiliar with Apple stuff so I might be wrong.
Can I store it in a binary file |
Sure can! Redirect the program's output (i.e.,
cout) to any file (
output.bin here). This will destroy the file's prior contents, if any exist:
echo "My message" | ./hash-encrypt encrypt my_password >output.bin
Then decrypt
output.bin by telling bash to use it as the input to
hash-encrypt:
<output.bin ./hash-encrypt decrypt my_password
I may be getting ahead of myself. The command
./hash-encrypt just runs the program named hash-encrypt in the current directory. The dot-slash means "current directory". It doesn't do anything, except print a diagnostic message.
The command
./hash-encrypt decrypt my_password
Gives the words "decrypt" and "my_password" to the program
./hash-encrypt by passing them to its
main function through the parameters
argv and
argc. That's how the program knows what to do. See this tutorial:
https://www.learncpp.com/cpp-tutorial/command-line-arguments/
If you run this command the program will read from
std::cin forever or until there is no more input. Type a brief message if you want, then tell the shell there is no more input by pressing Ctrl+D.
This isn't a very easy way to use the program; it will most likely print garbage all over the screen. That's where Bash comes in. The trick is figuring out how to tell Bash what to do.