9.4.11 adshvarconv command (converts the value of a variable)
Syntax
adshvarconv [-o] -p shell-variable-name [shell-variable-name ... ] adshvarconv [-o] [-c] -b character-string-before-conversion [-a character-string-after-conversion] shell-variable-name [shell-variable-name ... ] adshvarconv [-o] -i increase-of-\ shell-variable-name [shell-variable-name ... ] [only for Windows] adshvarconv [-o] [-u] -e encoding-before-conversion encoding-after-conversion shell-variable-name [shell-variable-name ... ]
Description
This command converts the value of a variable according to the option.
Options |
Function |
---|---|
-p |
This command converts the shell variable value according to the path conversion setting. |
-b, -a, -c |
This command converts the character-string-before-conversion into the character-string-after-conversion for the shell variable value. |
-i |
This command increases the number of \ in the shell variable value by the specified number. |
-e, -u |
This command executes the code conversion of the shell variable value. [Only for Windows] |
The description of the -o option is as follows:
-o option |
Output destination |
---|---|
Omitted |
This command updates the original shell variable value with the vale after conversion. |
Specified |
This command outputs the value after conversion to the standard output without changing the original shell variable value. |
Arguments
- -p
-
This command converts the value of the shell variable according to the path conversion setting (PATH_CONV_ENABLE and PATH_CONV environment setting parameters). The path is converted when executing the adshvarconv command. Therefore, when changing the value of the variable after executing the command, the value is not automatically converted. The value is not automatically converted even when the changed value is a value that matches the path conversion setting.
The behavior after converting the path is different from the conversion setting. The behavior of path conversion is as follows:
Path conversion actions
Each path separated with the path separator specified by PATH_CONV_ENABLE is converted with the PATH_CONV environment setting parameter.
Note: Although \\ is used as the separator symbol of Windows in the environment setting parameter, this command is converted by changing the number of \ from 2 to 1.
If the path is converted with the PATH_CONV environment setting parameter, the path separator and directory separator are converted into the separator of the corresponding OS.
Note: Although the separator symbol of Windows is converted into two backslashes (\\) by the normal path conversion functionality, the symbol is converted into a single backslash (\) by conversion using this command.
This command will not do anything when the path conversion functionality is disabled.
- -b character-string-before-conversion [-a character-string-after-conversion]
-
This command converts the character-string-before-conversion into the character-string-after-conversion for the shell variable value. If you do not specify -a, character-string-before-conversion is deleted.
character-string-before-conversion ~ <Any character string>((1 to 256 bytes))
character-string-after-conversion ~ <Any character string>((1 to 256 bytes))
- -c
-
This command executes conversion only when the path conversion functionality is available. This command will not do anything when the path conversion functionality is disabled. The path is converted unconditionally if the -c specification does not exist.
- -i increase-of-\
-
This command increases the number of \ in the shell variable value by the specified number for each character. If you specify -i 1 and the character string before conversion is abc\def\\ghi\\\jkl, the character string after conversion becomes abc\\def\\\\ghi\\\\\\jkl.
increase-of-\ ~ <3-digit decimal number>((1 to 256))
- -e encoding-before-conversion encoding-after-conversion [only for Windows]
-
Code conversion is executed for the value of the shell variable. variable-name
-
encoding-before-conversion ~ {SJIS | UTF8}
SJIS: Indicates that encoding is Shift-JIS.
UTF8: Indicates that encoding is UTF-8.
-
encoding-after-conversion ~ {SJIS | UTF8}
SJIS: Indicates that encoding is Shift-JIS.
UTF8: Indicates that encoding is UTF-8.
A validity check is not executed for the combination of the encoding before conversion and the encoding after conversion.
-
- -u
-
If there is a code that cannot be converted when executing code conversion, the code conversion will end in an error.
When the -u option is not specified, the process continues after converting the character that cannot be converted into a "?".
- -o
-
The value after conversion is output to the standard output. The shell variable value is not updated.
When the -o option is specified, you cannot specify multiple shell variable names. You cannot specify multiple elements with the array.
For options other than the -e option, the value of the variable before conversion is output to the standard output if the -o option exists even if conversion is not executed.
If conversion cannot be executed with the -e option, the result is not output to the standard output even if the -o option exists.
- shell-variable-name ~ <Shell variable name>((1 to 256))
-
The shell variable that changes the value needs to be specified. For the upper limit of the length of the array, the upper limit of the character string includes the specification of the argument.
You can specify the array in the following format:
The element number of the array can be specified from 0 to 65,535.
How to specify an array
Description
array[n]
nth element
array[@]
All elements
array[*]
All elements
array[]
Same as array[0]
array[n][m]
Element of line n and column m
array[n][@]
All elements of the nth line
array[n][*]
All elements of the nth line
array[n][]
Same as array[n][0]
array[@][m]
All elements of column m
array[@][@]
All elements
array[@][*]
All elements
array[@][]
All elements
array[*][m]
All elements of column m
array[*][@]
All elements
array[*][*]
All elements
array[*][]
All elements
array[][m]
Same as array[0][m]
array[][@]
All elements
array[][*]
All elements
array[][]
Same as array[0][0]
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 |
|
Notes
-
If the same variable is specified for multiple times, the variable is converted twice.
-
If the specified element does not exist in the variable of the array, subsequent variables are processed without being determined as an error.
-
If the specified variable name does not exist, subsequent variables are processed without being determined as an error.
-
If the value is processed with the right-justified attribute when a variable is stored, the value processed by the attribute is evaluated according to the conversion rule during the conversion according to the path conversion setting and the value might not be converted.
-
Note that the value after conversion might be processed depending on the attributes of the variable.
If the variable name is typeset-R10 (the area length is 10 characters with the right-justified format), truncation occurs according to the specification if the value after conversion exceeds the area length. If the value is shorter than the area length even after deleting the space characters at the beginning, one or more space characters are inserted at the beginning.
Examples
-
When the path of the parameter at the time of the start of the job definition script is specified and the path needs to be converted according to the conversion rule of PATH_CONV.
-
Environment setting parameters
#-adsh_conf PATH_CONV_ENABLE / : #-adsh_conf PATH_CONV_RULE 2 #-adsh_conf PATH_CONV /home/user001 "d:\\user001"
-
Job definition script (sample.ash)
infile=$1 adshvarconv -p infile "${ADSH_DIR_CMD}cat" ${infile}
-
Examples
D:\user001>cat d:\user001\zzzz.txt Data_zzzz.txt(d:\user001\zzzz.txt contents of file) D:\user001>adshexec -m MINIMUM sample.ash /home/user001/zzzz.txt Data_zzzz.txt(d:\user001\zzzz.txt contents of file)
-
-
When converting the path included in the file with the value of the argument:
-
Job definition script (sample.ash)
while read LINE do adshvarconv -b "/home/user1" -a "$1" LINE adshvarconv -b "/" -a "\\" LINE echo -E "$LINE" >&2 done < input.txt
-
input.txt
/home/user1/data001 /home/user1/data002
-
Examples
D:\user001>adshexec -m MINIMUM sample.ash D:/home/winuser001 D:\home\winuser001\data001 D:\home\winuser001\data002
-
-
When deleting the character string of \de from the input data:
-
Job definition script (sample.ash)
echo -E 'abc\de\kkk' >test.txt echo -E '123\de\kkk' >>test.txt "${ADSH_DIR_CMD}cat" test.txt >&2 echo -E start_sed >&2 "${ADSH_DIR_CMD}cat" test.txt | "${ADSH_DIR_CMD}sed" -e 's/\de//' >&2 echo -E start_adshvarconv >&2 while read -r LINE do adshvarconv -o -b '\de' LINE >&2 done < test.txt
-
Results
abc\de\kkk 123\de\kkk start_sed abc\\kkk 123\\kkk start_adshvarconv abc\kkk 123\kkk
As "\" in the character string specified for the pattern of the sed command is treated as an escape character, the character string of \de cannot be deleted correctly.
-
-
When increasing one \ when passing the path name to the awk command to prevent the \ from being deleted upon processing of an escape letter.
-
Job definition script (sample.ash)
aa=d:\\g1234z\\azzzz echo -E 'hitachi' | "${ADSH_DIR_CMD}awk" -v VVV1=$aa '/hitachi/ { \ print "VVV1=" VVV1 ; \ }' >&2 adshvarconv -i 1 aa echo -E 'hitachi' | "${ADSH_DIR_CMD}awk" -v VVV1=$aa '/hitachi/ { \ print "VVV1=" VVV1 ; \ }' >&2
-
Examples
D:\user001>adshexec -m MINIMUM sample.ash VVV1=d:g1234zzzzz VVV1=d:\g1234z\azzzz
-
-
When loading a file with read and converting the encoding from UTF-8 to Shift-JIS.
-
Job definition script file (sample1.ash)
echo -E "--- before ---" "${ADSH_DIR_CMD}ls" outdir while read LINE do "${ADSH_DIR_CMD}cp" $(adshvarconv -o -e UTF8 SJIS LINE) outdir done < input.txt echo -E "--- after ---" "${ADSH_DIR_CMD}ls" outdir
-
Input.txt file (UTF-8)
Tokyo.txt Kyoto.txt
-
Examples
D:\user001>adshexec -m MINIMUM sample.ash --- before --- --- after --- Kyoto.txt Tokyo.txt
-