Closed sc0ttj closed 5 years ago
The following solution reads from a file if the script is called with a file name as the first parameter $1 otherwise from standard input.
while IFS= read -r line
do
echo "$line"
done < "${1:-/dev/stdin}"
... Also see:
To read from the file or stdin (if argument is not present), you can extend it to:
file=${1--} # POSIX-compliant; ${1:--} can be used either.
while IFS= read -r line; do
printf '%s\n' "$line" # Or: env POSIXLY_CORRECT=1 echo "$line"
done < <(cat -- "$file")
Notes:
- read -r - Do not treat a backslash character in any special way. Consider each backslash to be part of the input line.
- Without setting IFS, by default the sequences of Space and Tab at the beginning and end of the lines are ignored (trimmed).
- Use printf instead of echo to avoid printing empty lines when the line consists of a single -e, -n or -E. However there is a workaround by using env POSIXLY_CORRECT=1 echo "$line" which executes your external GNU echo which supports it. See: How do I echo "-e"?
Done.. Added a new script called mdsh2md
... And create_page
will now rebuild from mdsh if passed the mdsh as $1 .. Also, updated update_pages
, so it now has a -ALL
option, which updates from mdsh, not just from md (like `-all)..
So in other words, it now works like so:
create_page file.mdsh > file.html # generate md file, then html file
create_page file.md > file.html # generate html file
and
update_pages -all # rebuild all HTML files from their md files
update_pages -ALL # rebuild all md and HTML files from their mdsh files
Using -ALL
is a bit slower, but not too bad .. Although it depends on the commands you embed on your mdsh files... Slow commands are the bottle neck.
Currently there is not way to re-generate a
.md
file from its.mdsh
source file.The
mdshell
script can only take input from the terminal, line by line. It cannot read a file line by line.In order to update existing pages, the user must edit the
.md
files, and runupdates_pages
to re-build the HTML.So far it all works like this:
create_post
:.mdsh
file.md
filecreate_page
:.md
file.html
file..we need
create_post
to also take an.mdsh
file as$1
, and to build a valid.md
file from it.Then, we can do the following:
create_post path/to/file.mdsh > path/to/output-file.md
This will leave us with the following rebuild options:
.md
to.html
)mdsh
(.mdsh
to.md
to.html
)