YaST2 Developers Documentation: The YCP standard built-in functions | ![]() |
![]() |
The YCP standard built-in functions
Logical not for booleans. Example: !false -> true
Negative of float.
Negative of integer.
Translates the text using a locale-aware plural form handling and the current textdomain. The chosen form of the translation depends on the value. Example _("%1 File", "%1 Files", 2) -> "%1 soubory"
Translates the text using the current textdomain. Example _("File") -> "Soubor"
Creates a new list that is identical to the list l but has the value v appended as additional element. Example: add ([1, 4], 8) -> [1, 4, 8]
Adds the key/value pair k : v to the map m and returns the newly Created map. If the key k exists in k, the old key/value pair is replaced with the new one. Example: add ($[a: 17, b: 11], `b, nil) -> $[a:17, b:nil].
Returns p with added path element created from string s. Example: add (.aaa, "anypath...\n\"") -> .aaa."anypath...\n\""
Adds the value v to the term t and returns the newly created term. As always in YCP, t is not modified. Example: add (sym (a), b) -> sym (a, b)
Returns the arguments of a term. Example: argsof (`fun(1, 2)) -> [1, 2]
Logical and for booleans. Example: false && true -> false
Logical or for booleans. Example: false || true -> true
DO NOT use this yet. Its for a special requst, not for common use!!! changes the list l adds a new element Example: change ([1, 4], 8) -> [1, 4, 8]
DO NOT use this yet. It's for a special requst, not for common use!!! Adds the key/value pair k : v to the map m and returns the map. m is modified. If the key k exists in k, the old key/value pair is replaced with the new one. Example: change ($[.a: 17, .b: 11], .b, nil) -> $[.a:17, .b:nil].
Determines, if a certain value v is contained in a list l. Returns true, if this is so. Example: contains ([1, 2, 5], 2) -> true
Encrypt the string unencrypted using the standard password encryption provided by the system. Example: crypt ("readable") -> "Y2PEyAiaeaFy6"
Encrypt the string unencrypted using bigcrypt password encryption. The password is not truncated. Example cryptbigcrypt ("readable") -> "d4brTQmcVbtNg"
Encrypt the string unencrypted using blowfish password encryption. The password is not truncated. Example cryptblowfish ("readable") -> "$2a$05$B3lAUExB.Bqpy8Pq0TpZt.s7EydrmxJRuhOZR04YG01ptwOUR147C"
Encrypt the string unencrypted using md5 password encryption. Example: crypt ("readable") -> "WEgvferaeaFy6"
Returns a string that results from string s by removing all characters that occur in remove. Example: deletechars ("aÖBÄc", "abcdefghijklmnopqrstuvwxyz") -> "ÖBÄ"
Translates the text using the given text domain into the current language. This is a special case builtin not intended for general use. See _() instead. Example dgettext ("base", "No") -> "Nie"
Translates the text using a locale-aware plural form handling using the given textdomain. The chosen form of the translation depend on the value. This is a special case builtin not intended for general use. See _() instead. Example dngettext ("base", "%1 File", "%1 Files", 2) -> "%1 soubory"
Evaluate a YCP value. See also the builtin ``, which is kind of the counterpart to eval. Examples: eval (``(1+2)) -> 3 { term a = ``add(); a = add(a, [1]); a = add(a, 4); return eval(a); } -> [1,4]
For each key/value pair of the map m the expression exp is evaluated in a new context, where the variable k is assigned to the key and v to the value of the pair. If the expression evaluates to true, the key/value pair is appended to the returned map. Example: filter (`k, `v, $[1:"a", 2:"b", 3:3, 5:5], { return (k == v); }) -> $[3:3, 5:5]
For each element of the list l the expression v is executed in a new context, where the variable s is assigned to that value. If the expression evaluates to true under this circumstances, the value is appended to the result list. Example: filter (`v, [1, 2, 3, 5], { return (v > 2); }) -> [3, 5]
Returns a string that results from string s by removing all characters that do not occur in include. Example: filterchars ("aÖBÄc", "abcdefghijklmnopqrstuvwxyz") -> "ac"
Returns the first position in s1 where the string s2 is contained in s1. Examples: find ("abcdefghi", "efg") -> 4 find ("aaaaa", "z") -> -1
Searches for a certain item in the list. It applies the expression e to each element in the list and returns the first element the makes the expression evaluate to true, if s is bound to that element. Returns nil, if none is found. Example: find (`n, [3,5,6,4], ``(n >= 5)) -> 5
Returns the position of the first character in s1 that is not contained in s2. Examples: findfirstnotof ("abcdefghi", "abcefghi") -> 3 findfirstnotof ("aaaaa", "a") -> nil
Returns the position of the first character in s1 that is contained in s2. Examples: findfirstof ("abcdefghi", "cxdv") -> 2 findfirstof ("aaaaa", "z") -> nil
Returns the position of the last character in s_1 that is NOT contained in s_2. Example findlastnotof( "abcdefghi", "abcefghi" ) -> 3 ('d') findlastnotof("aaaaa", "a") -> nil
Returns the position of the last character in s1 that is contained in s2. Examples: findlastof ("abcdecfghi", "cxdv") -> 5 findlastof ("aaaaa", "z") -> nil
Gets a list l of lists and creates a single list that is the concatenation of those lists in l. Example: flatten ([ [1, 2], [3, 4] ]) -> [1, 2, 3, 4]
Multiplication of floats. Example: 1.5 * 2.5 -> 3.75
Division of floats. Example: 1.5 / 2.5 -> 0.6
Addition of floats. Example: 1.5 + 2.5 -> 4.0
Subtraction of floats. Example: 1.5 - 2.5 -> -1.0
For each key:value pair of the map m the expression exp is executed in a new context, where the variables key is bound to the key and value is bound to the value. The return value of the last execution of exp is the value of the foreach construct. Example foreach (integer k, integer v, $[1:1,2:4,3:9], { y2debug("v = %1", v); return v; }) -> 9
For each element of the list l the expression exp is executed in a new context, where the variable s is assigned to that value. The return value of the last execution of exp is the value of the foreach construct. Example foreach (integer v, [1,2,3], { return v; }) -> 3
Determines whether the map m contains a pair with the key k. Returns true if this is so.
Modulus of integers. Examples: 7 % 4 -> 3
Bitwise and of integers. Examples: 13 & 8 -> 8 13 & 7 -> 5
Multiplication of integers. Example: 2 * 3 -> 6
Addition of integers. Example: 1 + 2 -> 3
Subtraction of integers. Example: 1 - 2 -> -1
Division of integers. Examples: 6 / 2 -> 3 42 / 0 -> nil
Bitwise shift left for integers. Example: 8 << 2 -> 32
Bitwise shift right for integers. Example: 8 >> 2 -> 2
Bitwise exclusive or of integers. Examples: 2 ^ 7 -> 5 5 ^ 4 -> 1
Bitwise or of integers. Examples: 2 | 2 -> 2 1 | 4 -> 5
Return true, if substring is a substring of s. Example: issubstring ("some text", "tex") -> true
Maps an operation onto all elements of a list and thus creates a map. For each element k of the list l in the expression exp is evaluated in a new context. The result is the map of those evaluations. The result of each evaluation must be a list with two items. The first item is the key of the new mapentry, the second is the value of the new entry. Examples: listmap (`k, [1,2,3], { return [k, "xy"]; }) -> $[ 1:"xy", 2:"xy" ] listmap (`k, [1,2,3], { any a = k+10; any b = sformat("x%1",k); list ret = [a,b]; return (ret); }) -> $[ 11:"x1", 12:"x2", 13:"x3" ]
Maps an operation onto all elements key/value pairs of a map and thus creates a list. For each key/value pair of the map m the expression e is evaluated in a new context, where the variable k is assigned to the key and v to the value of the pair. The result is the list of those evaluations. Example: maplist (`k, `v, $[1:"a", 2:"b"], { return [k+10, v+"x"]; }) -> [ [11, "ax"], [ 12, "bx" ] ]
Maps an operation onto all elements of a list and thus creates a new list. For each element of the list l the expression v is evaluated in a new context, where the variable s is assigned to that value. The result is the list of those evaluations. Example: maplist (`v, [1, 2, 3, 5], { return (v + 1); }) -> [2, 3, 4, 6]
Maps an operation onto all key/value pairs of the map m and thus creates a new map. For each key/value pair of the map m the expression exp is evaluated in a new context, where the variable k is assigned to the key and v to the value of the pair. The result is the map of those evaluations. The result of each evaluation must be a map with a single entry which will be added to the result map. Examples: mapmap (`k, `v, $[1:"a", 2:"b"], { return ($[k+10 : v+"x"]); }) -> $[ 11:"ax", 12:"bx" ] mapmap (`k, `v, $[1:"a", 2:"b"], { any a = k+10; any b = v+"x"; map ret = $[a:b]; return (ret); }) -> $[ 11:"ax", 12:"bx" ]
Interprets two lists as sets and returns a new list that has all elements of the first list and all of the second list. Identical elements are preserved. The order of the elements in the new list is preserved. Elements of l1 are prior to elements from l2. See also "union". Examples: merge ([1, 2], [3, 4]) -> [1, 2, 3, 4] merge ([1, 2, 3], [2, 3, 4]) -> [1, 2, 3, 2, 3, 4]
Merges a list of strings to a single list. Inserts c between list elements (c may be empty). List elements which are not of type strings are ignored. See also: splitstring Examples: mergestring (["", "abc", "dev", "ghi"], "/") -> "/abc/dev/ghi" mergestring (["abc", "dev", "ghi", ""], "/") -> "abc/dev/ghi/" mergestring ([1, "a", 3], ".") -> "a" mergestring ([], ".") -> "" mergestring (["abc", "dev", "ghi"], "") -> "abcdevghi" mergestring (["abc", "dev", "ghi"], "123") -> "abc123dev123ghi"
Returns p1 with added p2 element created from string s. Example: .aaa + "anypath...\n\"" -> .aaa."anypath...\n\""
Creates a new list that is identical to the list l but has the value v prepended as additional element. Example: prepend ([1, 4], 8) -> [8, 1, 4]
Random number generator. Returns integer in the interval <0,max).
Examples: regexpmatch ("aaabbb", ".*ab.*") -> true regexpmatch ("aaabbb", ".*ba.*") -> false
Returns a list with position and length of the first match, if no match is found it returns an empty list. Example regexppos( "abcd012efgh345", "[0-9]+" ) -> [4, 3] regexppos( "aaabbb", "[0-9]+" ) -> []
Examples: regexpsub ("aaabbb", "(.*ab).*", "s_\\1_e") -> "s_aaab_e" regexpsub ("aaabbb", "(.*ba).*", "s_\\1_e") -> nil
!Attention pattern have to include parenthesize "(" ")" If you need no parenthesize, use regexp_match If the pattern does not not match, the list ist empty. Otherwise the list contains then matchted subexpressions for each pair of parenthesize in pattern. If pattern does not contain a valid pattern, nil is returned. In the include "common_functions, there are some convinience function, like tokenX or regexp_error Examples: list e = regexptokenize ("aaabbBb", "(.*[A-Z]).*")
Remove the i'th value from a list. The first value has the index 0. The call remove ([1,2,3], 1) thus returns [1,3]. Returns nil if the index is invalid. Example: remove ([1, 2], 0) -> [2]
Remove the value with the key key from a map. Returns nil if the key is invalid. Example: remove($[1:2], 0) -> nil remove ($[1:2, 3:4], 1) -> $[3:4]
Remove the i'th value from a term. The first value has the index 1 (!). (The index counting is for compatibility reasons with the 'old' remove which allowed 'remove(`term(1,2,3), 0) = [1,2,3]' Use 'argsof (term) -> list' for this kind of transformation.) Example: remove (`fun(1, 2), 1) -> `fun(2)
Gets the i'th value of a list. The first value has the index 0. The call select([1,2,3], 1) thus returns 2. Returns default if the index is invalid or if the found entry has a different type than the default value. Examples: select ([1, 2], 22, 0) -> 0 select ([1, "two"], 0, "no") -> "no"
Gets the i'th value of the term t. The first value has the index 0. The call select ([1, 2, 3], 1) thus returns 2. Returns the default if the index is invalid or the found value has a diffetent type that default. Example: select (`hirn (true, false), 33, true) -> true
Determines, if a certain value v is contained in a list l, but assumes that l is sorted. If l is not sorted, the result is undefined. Example: setcontains ([1, 2, 5], 2) -> true
form is a string that may contains placeholders %1, %2, ... Each placeholder is substituted with the argument converted to string whose number is after the %. Only 1-9 are allowed by now. The percentage sign is donated with %%. Example: sformat ("%2 is greater %% than %1", 3, "five") -> "five is greater % than 3"
Returns a size of a byteblock in bytes.
Returns the number of elements of the list l
Returns the number of key/value pairs in the map m
Returns the number of path elements of the path p, i.e. the length of p. Examples: size (.hello.world) -> 2 size (.) -> 0
Returns the number of characters of the string s Notice, that size(nil) -> nil
Returns the number of arguments of the term t.
Sleeps a number of milliseconds.
Sort the list l according to the YCP builtin predicate <. Duplicates are not removed. Example: sort ([2, 1, true, 1]) -> [true, 1, 1, 2]
Sorts the list l. You have to specify an order on the list elements by naming to formal variables x und y and specify an expression order, that evaluates to a boolean value depending on x and y. Return true, if x < y to sort the list ascending. The comparison must be an irreflexive one, that is "<" instead of "<=". It is because we no longer use bubblesort (yuck) but std::sort which requires a strict weak ordering. Examples: sort (integer x, integer y, [ 3,6,2,8 ], ``(x < y)) -> [ 2, 3, 6, 8 ]
Splits s into sub-strings at delimter chars c. the resulting pieces do not contain c see also: mergestring If s starts with c, the first string in the result list is empty If s ends with c, the last string in the result list is empty. If s does not contain c, the result is a list with s. Examples: splitstring ("/abc/dev/ghi", "/") -> ["", "abc", "dev", "ghi" ] splitstring ("abc/dev/ghi/", "/") -> ["abc", "dev", "ghi", "" ] splitstring ("abc/dev/ghi/", ".") -> ["abc/dev/ghi/" ] splitstring ("text/with:different/separators", "/:") -> ["text", "with", "different", "separators"]
Initialize random number generator with current date and time and returns the seed.
Initialize random number generator.
Returns concatenation of s1 and i2 after transforming i2 to a string. Example: "YaST" + 2 -> "YaST2"
Returns concatenation of s1 and p2 after transforming p2 to a string. Example: "YaST" + .two -> "YaST.two"
Returns concatenation of s1 and s2. Example: "YaST" + "2" -> "YaST2"
Returns concatenation of s1 and s2 after transforming s2 to a string AND stripping the leading backquote. Example: "YaST" + `two -> "YaSTtwo"
Extract a substring of the string s, starting at start after the first one. Examples: substring ("some text", 5) -> "text" substring ("some text", 42) -> ""
Extract a substring of the string s, starting at start after the first one with length of at most length. Example: substring ("some text", 5, 2) -> "te" substring ("some text", 42, 2) -> ""
Returns the symbol of the term t. Example: symbolof (`hrombuch (18, false)) -> `hrombuch
Return the number of seconds since 1.1.1970.
Combination of standard libc functions gmtime or localtime and strftime. Example timestring ("", 100, false) -> ""
Returns a string that results from string s by copying each character that is below 0x7F (127). Example: toascii ("aÖBÄc") -> "aBc"
Converts a value to a byteblock. If the value can't be converted to a byteblock, nilbyteblock is returned.
Converts a value to a floating point number. If the value can't be converted to a float, nilfloat is returned. Example: tofloat (4) -> 4.0 tofloat ("42") -> 42.0 tofloat ("3.14") -> 3.14
Converts a integer to a hexadecimal string. Example: tohexstring (31) -> "0x1f"
Converts a value to an integer. If the value can't be converted to an integer, nilinteger is returned. Example: tointeger (4.03) -> 4 tointeger ("42") -> 42 tointeger ("0x42") -> 66 tointeger ("042") -> 34
Converts a value to a list. If the value can't be converted to a list, nillist is returned.
Returns a string that results from string s by converting each character tolower. Example: tolower ("aBcDeF") -> "abcdef"
Converts a value to a map. If the value can't be converted to a map, nilmap is returned.
Converts a value to a path. If the value can't be converted to a path, nilpath is returned. Example: topath ("path") -> .path topath (".some.path") -> .some.path
Scans a list for duplicates, removes them and sorts the list. Example: toset ([1, 5, 3, 2, 3, true, false, true]) -> [false, true, 1, 2, 3, 5]
Converts a value to a string.
Converts a floating point number to a string, using the specified precision. Example: tostring (0.12345, 4) -> 0.1235
Converts a value to a term. If the value can't be converted to a term, nilterm is returned.
Returns a string that results from string s by converting each character toupper. Example: tolower ("aBcDeF") -> "ABCDEF"
Interprets two lists as sets and returns a new list that has all elements of the first list and all of the second list. Identical elements are dropped. The order of the elements in the new list is preserved. Elements of l1 are prior to elements from l2. See also "mergelist". Examples: union ([1, 2], [3, 4]) -> [1, 2, 3, 4] union ([1, 2, 3], [2, 3, 4]) -> [1, 2, 3, 4]
Interprets two maps as sets and returns a new map that has all elements of the first map m1>/tt>and all of the second map m2. If elements have identical keys, values from m2 overwrite elements from m1.
Log a message to the y2log. Arguments are same as for sformat() builtin. The y2log component is "YCP", so you can control these messages the same way as other y2log messages. Example: y2debug ("%1 is smaller than %2", 7, "13");
Bitwise not of integer. Example: ~42 = -43 |
YaST2 Developers Documentation: The YCP standard built-in functions | ![]() |