I want to use the content of a file.txt as part of a bash command. Suppose that the bash command with its options that I want to execute is:
my_command -a first value --b_long_version_option="second value" -c third_value
but the first 2 options (-a and --b_long_version_option ) are very verbose so instead of inserting directly on the command line (or bash script) I wrote them in a file.txt like this:
-a first value \
--b_long_version_option="second value"
Now I expect to call the command "my_command" with the following syntax (where "path_to/file.txt" is the path to file.txt, expressed in relative or absolute form):
my_command "$(cat path_to/file.txt)" -c third_value
This however is not the right syntax, as my command is breaking and complaining.
How should I write the new version of the command and/or the file.txt so that it is equivalent to its native bash usage?
Thanks in advance!
I haven't seen any example of what you're trying. But, there are simpler ways to achieve your goal.
Bash Alias
ll
for example is a bash alias forls -al
. It usually is defined in.bash_profile
or.bashrc
as follows :So, what you can do is to set another alias for your shorthand command.
then you can use it as follows :
Config file
You can also define a mycommand.json file or mycommand.ini file for default arguments. Then, you will need to check for config file in your software, and assign arguments from it.
Using config file is more advanced solution. You can define multiple config files. You can set default config file in
/etc/mycommand/config.ini
for example. When running on different directories, you should check${cwd}/mycommand.ini
to check local config file exists or not. You can even add a--config-file
argument to your command.Using alias is more convenient for small tasks, or thing that won't change much. If your command's behavior should be different in some other project, the using a config file would be a better solution.