I do not know how to write that part of bash script which enables me to write to the file which is created in the middle of the script (because it depends on user input) but I want to write output from the beginning.
Example:
#!/bin/bash
<start_of_logging>
<code>
read -p "Enter your city: " city
touch ${city}
<code>
<end_of_logging>
Script does not know what user put in city
so if I am correct I am not able to logging from <start_of_logging>
part or is there any workaround? I mean I want to log everything from the beginning and write it out to the file which is called like a city provided by an user.
/tmp/myIniqName
, andmv
this file as soon as you find what the final name should be. (2) Send your log lines to an array until you find the final name, then write out the array to the file, and send subsequent logs to the real file.mv
approach. Thanks @Paul_Pedant../Memphis.log
, including any logging done before the user enters hiscity
.mktemp
to create the log file (instead of using some fixed initial name), unless the computer is strictly single-user.