tutorials:bash_scripting:part1
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorials:bash_scripting:part1 [2012/02/26 05:52] – rmiles | tutorials:bash_scripting:part1 [2017/10/12 21:58] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | **1. Converting a scanned document to a pdf document** | + | //**1. Converting a scanned document to a pdf document**// |
+ | ---- | ||
Last year I did some consulting for a law firm that required me to submit time sheets with my invoices. In any given invoice period I would undertake work involving multiple clients. Work undertaken for each client was broken down into standard categories, telephone call, email, meeting, etc. | Last year I did some consulting for a law firm that required me to submit time sheets with my invoices. In any given invoice period I would undertake work involving multiple clients. Work undertaken for each client was broken down into standard categories, telephone call, email, meeting, etc. | ||
Line 41: | Line 42: | ||
I will now explain how this script works: | I will now explain how this script works: | ||
- | Note that with the exception of the first line, any text prefixed with a hash, //#//, is ignored up until the next new line. Text prefixed with a hash is usually referred to as a comment. Comments can be put on the same line as a command but only after the command. There are no hard and fast rules about using comments. They are handy to explain things to other folks as well as oneself. I normally don't comment a small script as much as this one. Usually I just add some notes at the top and then add what I need as I go along to explain | + | Note that with the exception of the first line, any text prefixed with a hash, //#//, is ignored up until the next new line. Text prefixed with a hash is usually referred to as a comment. Comments can be put on the same line as a command but only after the command. There are no hard and fast rules about using comments. They are handy to explain things to other folks as well as oneself. I normally don't comment a small script as much as this one. Usually I just add some notes at the top and then perhaps |
<code bash> | <code bash> | ||
#!/bin/bash | #!/bin/bash | ||
Line 59: | Line 59: | ||
</ | </ | ||
- | This line uses //test// a bash built in command (builtin) to test if the variable is a non zero string, i.e. if a file name was passed to the script when the command // | + | This line uses //test// a bash built in command (builtin) to test if the variable is a non zero string, i.e. if a file name was passed to the script when the command // |
<code bash> | <code bash> | ||
Line 81: | Line 81: | ||
</ | </ | ||
- | Instead of passing both an input filename and an output (save) filename to the script the next line to creates and assigns | + | Instead of passing both an input filename and an output (save) filename to the script the next line to assign |
- | In the command | + | In this line echo is used to print the variable // |
- | //Awk// or //gawk// is a pattern matching program. Here the flag //-F// is used to declare //" | + | //Awk//, or //gawk//, is a pattern matching program. Here the flag //-F// is used to declare //" |
+ | |||
+ | Note //.pdf// on the same line, after the second backtick. This appends //.pdf// to //$1// so if //$1// was scanned_file, | ||
+ | |||
+ | You will find that there are often more than one way to do something when scripting. The command //cut// could also have been used in place of awk. | ||
+ | |||
+ | <code bash> | ||
+ | output_file=`echo " | ||
+ | </ | ||
- | Note //.pdf// on the same line, after the second backtick. This appends | + | Field separators are also referred to as delimiters. In the above line, //-d.// nominates full stop as the delimiter and //-f1// selects field 1 for printing to stdout. |
<code bash> | <code bash> | ||
Line 102: | Line 110: | ||
---- | ---- | ||
- | I almost always have a terminal open so my scripts are usually intended to be run on the command line. After saving the scanned image into the directory where the relevant pdf records were kept I would //cd// into that directory and run the command //con2pdf [image name]//. | + | //I almost always have a terminal open so my scripts are usually intended to be run on the command line. After saving the scanned image into the directory where the relevant pdf records were kept I would //cd// into that directory and run the command //con2pdf [image name]//. |
- | In the next section I'll show how to modify //con2pdf// so that it will have a gui interface for both selecting the image file and selecting a path and name for the resulting .pdf file | + | In the next section I'll show how to modify //con2pdf// so that it will have a gui interface for both selecting the image file and selecting a path and name for the resulting .pdf file// |
---- | ---- | ||
+ | **Cheers!** |
tutorials/bash_scripting/part1.1330195967.txt.gz · Last modified: 2017/10/12 21:58 (external edit)