Shell Specific Behavior
How to cope with various shell restrictions
Generally: quote commands with blank spaces or special characters
On every shell a white space usually separates one command line argument from the previous and the next one.
Other characters might be used for certain shell-specific functions.
If such characters or blank spaces occur, it is always necessary to quote the command or at least the expression embedding it, to prevent "misunderstandings".
Windows Batch files: the code page problem
Here is what can be done if umlauts are necessary when calling csvfox.
The following Windows batch file (something.bat) is in ANSI format (here: Windows-1252).
It needs the Euro (€) sign, but the standard code page 850 does not support this character.
So the batch file temporarily switches to codepage 1252, and defines the variable "euro" (later on referred as "%euro%"), before it switches back to code page 850.
After this, it calls csvfox with command parameters, and on every place where "€" would be needed, it uses "%euro%" instead.
@echo off &setlocal chcp 1252>nul set "euro=€" chcp 850>nul csvfox kfz.csv +rename[Price],[Brand]=NetPrice,CarType %[Tax]=1.19 +add[GrossPrice]=(([NetPrice])*[Tax]) +add[Phrase]="My new [CarType] costs {([GrossPrice])2} %euro%!" +add[Expensive]={(([NetPrice])*1)2} car-done.csv %log=log-%%Y.txt
A different way to handle this might be using the %job, %j option.
A %job file contains all commands that otherwise would have been csvfox parameters, and has UTF-8 or the local Windows default encoding (e.g. CP1252 = Windows-1252). So if you place the commands there, you overcome the restrictions of the CP850 commandline processor, you can place empty lines and comments, and you can also use the locally supported diacritical characters directly.
So the same work can be done using this %job file:
myjobfile.txt
Additionally, a %job file can have an explicit encoding:
%job/utf-8=myjobfile.txt
so if you work with UTF-8 is is also possible to embed any code point of unicode charset.
Linux bash: avoid expansion
In some requirements, special characters, like brackets, must be escaped through prepending a backslash "\". This is e.g. required for accessing column names that contain brackets themself. See also here: CSV Field Access
But Linux bash consumes the backslash for itself (for its own escaping needs) and removes it from the command.
There two different ways to handle this:
- Enclose the concerned command with double quotes.
- Complement each backslash with a second backslash, ie. double the backslash.
Moreover, Linux shell immediately expands wildcards like * and ? as placeholders for file names, instead of forwarding these signs to the called program.
You can suppress this expansion with the setting "-f". Or set +H.
This can be done this way:
- set -f
csvfox input.csv (more commands)
set +f
or
set +H
csvfox input.csv (more commands)
set -H
Powershell: avoid special characters handling
Use "--%" as the first parameter for csvfox, if using powershell.
This will stop handling #, % etc. as special functions, and allow the shell to interpret them as characters.
If used often, it might be a good idea to prepare a csvfox command script that always inserts the "--%" parameter as a first argument.
cmd /c 'csvfox ...' is an alternative to --%.
Please pay attention to the single quotes which must surround the whole command line!
überprüfen!
@ as first char in at parameter wird leider immer noch vergessen.