declare

Why are “declare -f” and “declare -a” needed in bash scripts?

一曲冷凌霜 提交于 2019-12-03 19:48:00
问题 Sorry for so innocent question - I just try to undertand... For example - I have: $ cat test.sh #!/bin/bash declare -f testfunct testfunct () { echo "I'm function" } testfunct declare -a testarr testarr=([1]=arr1 [2]=arr2 [3]=arr3) echo ${testarr[@]} And when I run it I get: $ ./test.sh I'm function arr1 arr2 arr3 So here is a question - for what i must (if must...) insert declare here? With it - or without it it works the same... I can understand for example declare -i var or declare -r var

create triggers - error at DECLARE

∥☆過路亽.° 提交于 2019-12-03 18:15:22
问题 i learn triggers from http://forge.mysql.com/wiki/Triggers and i have: create trigger bi_emps_fer before insert on emps for each row begin declare newsal numeric default 0; declare namelength, l_loop int default 0; set namelength = length(new.emp_name); while l_loop < namelength do set newsal := newsal new.salary; set l_loop := l_loop 1; end while; set new.salary = newsal; end and error: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server

Why don't methods of structs have to be declared in C++?

送分小仙女□ 提交于 2019-12-03 09:27:48
Take, for example, the following code: #include <iostream> #include <string> int main() { print("Hello!"); } void print(std::string s) { std::cout << s << std::endl; } When trying to build this, I get the following: program.cpp: In function ‘int main()’: program.cpp:6:16: error: ‘print’ was not declared in this scope Which makes sense. So why can I conduct a similar concept in a struct, but not get yelled at for it? struct Snake { ... Snake() { ... addBlock(Block(...)); } void addBlock(Block block) { ... } void update() { ... } } snake1; Not only do I not get warnings, but the program actually

Declare a void function in C?

送分小仙女□ 提交于 2019-12-03 09:02:49
I am learning C and I am studying functions. So, I read that when I implement my own function I have to declare it before the main(). If I miss the declaration the compiler will get an error message. As I was studying this example (finds if the number is a prime number) #include <stdio.h> void prime(); //function prototype(declaration) int main() { int num,i,flag; num = input(); // No argument is passed to input() for(i=2,flag=i; i<=num/2; ++i,flag=i) { flag = i; if(num%i==0) { printf("%d is not prime\n",num); ++flag; break; } } if(flag==i) printf("%d is prime\n",num); return 0; } int input()

Differences between declare, typeset and local variable in Bash

人走茶凉 提交于 2019-12-03 04:43:50
问题 When typing variables in Bash, what is the difference between declare and typeset ? When used inside a function: what is the difference between declare and typeset and local ? The only difference I have come across is that typeset is portable to ksh scripts. Other than that, are there any reasons why one should be preferred over the other? UPDATE: Added local to the question. 回答1: Difference between typeset and declare : The former is more portable(e.g. ksh), while the latter is more

What does “#!/bin/env” mean (at the top of a node.js script)?

社会主义新天地 提交于 2019-12-03 02:57:22
问题 I found serval node.js projects that have this at top of their app.js (as in this openshift program): #!/bin/env node What does this mean? How does this work? Where is it useful? 回答1: The full line from your example is: #!/bin/env node This simply means that the script should be executed with the first executable named 'node' that's found in your current PATH. The shebang (#!) at the start means execute the script with what follows. /bin/env is a standard unix program that looks at your

MySQL local variables

两盒软妹~` 提交于 2019-12-03 01:10:59
I am trying to define and initialize a MySQL variable for a query. I have the following: declare @countTotal int; SET @countTotal = select COUNT(*) from nGrams; I am using MySQL in Netbeans and it tells me I have an error. What/where is my error? How can I fix this? MySQL has two different types of variable: local variables (which are not prefixed by @ ) are strongly typed and scoped to the stored program block in which they are declared. Note that, as documented under DECLARE Syntax : DECLARE is permitted only inside a BEGIN ... END compound statement and must be at its start, before any

Differences between declare, typeset and local variable in Bash

时光怂恿深爱的人放手 提交于 2019-12-02 19:01:49
When typing variables in Bash, what is the difference between declare and typeset ? When used inside a function: what is the difference between declare and typeset and local ? The only difference I have come across is that typeset is portable to ksh scripts. Other than that, are there any reasons why one should be preferred over the other? UPDATE: Added local to the question. Difference between typeset and declare : The former is more portable(e.g. ksh), while the latter is more preferable when portability is not a concern. Difference between declare (or typeset ) and local when used inside a

Calloc for an array of array with negative index in C

我的未来我决定 提交于 2019-12-02 17:45:37
问题 I have an array of array with negative index. It is an array which has real dimensions [dim_y + 40][dim_x + 40] but the user uses the array like it has dimensions [dim_y][dim_x]. First i had global and already defined the dimensions dim_x, dim_y, so i had this int map_boundaries[dim_y + 40][dim_x + 40]; int (*map)[dim_x+40] = (int(*)[dim_x+40])&map_boundaries[20][20]; It worked fine. Now i need the dimensions dim_y and dim_x to be variable, and with this i mean that i want the array 'map' to

What does “#!/bin/env” mean (at the top of a node.js script)?

*爱你&永不变心* 提交于 2019-12-02 16:31:27
I found serval node.js projects that have this at top of their app.js (as in this openshift program ): #!/bin/env node What does this mean? How does this work? Where is it useful? The full line from your example is: #!/bin/env node This simply means that the script should be executed with the first executable named 'node' that's found in your current PATH. The shebang (#!) at the start means execute the script with what follows. /bin/env is a standard unix program that looks at your current environment. Any argument to it not in a 'name=value' format is a command to execute. See your env