If your $VARIABLE is a string containing spaces or other special characters, and single square brackets are used (which is a shortcut for the test command), then the string may be split out into multiple words. Each of these is treated as a separate argument.
So that one variable is split out into many arguments:
VARIABLE=$(/some/command);
# returns "hello world"
if [ $VARIABLE == 0 ]; then
# fails as if you wrote:
# if [ hello world == 0 ]
fi
The same will be true for any function call that puts down a string containing spaces or other special characters.
Easy fix
Wrap the variable output in double quotes, forcing it to stay as one string (therefore one argument). For example,
VARIABLE=$(/some/command);
if [ "$VARIABLE" == 0 ]; then
# some action
fi
Simple as that. But skip to «Also beware…» below if you also can’t guarantee your variable won’t be an empty string, or a string that contains nothing but whitespace.
Or, an alternate fix is to use double square brackets (which is a shortcut for the new test command).
This exists only in bash (and apparently korn and zsh) however, and so may not be compatible with default shells called by /bin/sh etc.
This means on some systems, it might work from the console but not when called elsewhere, like from cron, depending on how everything is configured.
It would look like this:
VARIABLE=$(/some/command);
if [[ $VARIABLE == 0 ]]; then
# some action
fi
If your command contains double square brackets like this and you get errors in logs but it works from the console, try swapping out the [[ for an alternative suggested here, or, ensure that whatever runs your script uses a shell that supports [[ aka new test.
Also beware of the [: unary operator expected error
If you’re seeing the «too many arguments» error, chances are you’re getting a string from a function with unpredictable output. If it’s also possible to get an empty string (or all whitespace string), this would be treated as zero arguments even with the above «quick fix», and would fail with [: unary operator expected
It’s the same ‘gotcha’ if you’re used to other languages — you don’t expect the contents of a variable to be effectively printed into the code like this before it is evaluated.
Here’s an example that prevents both the [: too many arguments and the [: unary operator expected errors: replacing the output with a default value if it is empty (in this example, 0), with double quotes wrapped around the whole thing:
VARIABLE=$(/some/command);
if [ "${VARIABLE:-0}" == 0 ]; then
# some action
fi
(here, the action will happen if $VARIABLE is 0, or empty. Naturally, you should change the 0 (the default value) to a different default value if different behaviour is wanted)
Final note: Since [ is a shortcut for test, all the above is also true for the error test: too many arguments (and also test: unary operator expected)
- Functions in C++
- the
too many arguments to functionError in C++ - Resolve the
too many arguments to functionError in C++ - Conclusion

We encounter a lot of errors while writing a piece of code. Solving errors is one of the most crucial parts of programming.
This article will discuss one error we encounter in C++: too many arguments to function.
Functions in C++
The too many arguments to function is an error in C++ that we encounter when we specify different arguments in the declaration and the implementation of a function.
To understand this error and fix it, we should first discuss what functions are.
A function is a block of code that is reusable and is used to perform repetitive tasks. Suppose we want to print "Hello World" in a program five times.
Now, one way to do so is to write the print statement every time we want to print it, whereas the other efficient way would be to make a function where the code to write "Hello World" would be written, and this function would be called whenever we need it.
The function that prints "Hello World" will be implemented below.
#include <iostream>
using namespace std;
void print();
int main() {
print();
print();
print();
print();
return 0;
}
void print(){
cout<<"Hello World"<<endl;
}
Output:
Hello World
Hello World
Hello World
Hello World
However, if we write the print() function after the main(), then we need to first declare the function before the main() so that the compiler knows that a function named print() exists in the program.
the too many arguments to function Error in C++
Arguments are values that are defined when a function is called. The too many arguments to function error occur because of these arguments in a function.
The number of arguments should be the same in the function call and the function declaration of a program. We get this error when the number of arguments is different in the function declaration and function call.
Let us see a code to depict what these different arguments mean. Below is the code snippet that throws an error stating that there are too many arguments in a function.
#include <iostream>
using namespace std;
void addition();
int main() {
addition(4,5);
return 0;
}
void addition(int a, int b){
cout<<"Addition of the numbers "<< a<< " and " << b <<" = " << (a+b)<<endl;
}
Output:
./6e359960-d9d7-4843-86c0-b9394abfab38.cpp: In function 'int main)':
./6e359960-d9d7-4843-86c0-b9394abfab38.cpp:7:14: error: too many arguments to function 'void addition)'
addition4,5);
^
./6e359960-d9d7-4843-86c0-b9394abfab38.cpp:4:6: note: declared here
void addition);
^
In the above code snippet, we have used the function addition() to add the two numbers. On the third line, we have declared the function addition() with no arguments (arguments are present in the parentheses of a function).
However, when we make or define the addition() function, we have passed two arguments, a and b, to it so that these two numbers can be added. Therefore, this mismatch in the number of arguments causes the too many arguments to function.
Resolve the too many arguments to function Error in C++
The too many arguments to function error in C++ can be resolved by considering the number of arguments passed to the function when declaring and defining it.
Let us take the same example as above and resolve its error.
#include <iostream>
using namespace std;
void addition(int,int);
int main() {
addition(4,5);
return 0;
}
void addition(int a, int b){
cout<<"Addition of the numbers "<< a<< " and " << b <<" = " << (a+b)<<endl;
}
Output:
Addition of the numbers 4 and 5 = 9
Therefore, as you can see, the error has been removed, and our result of adding two numbers has been displayed successfully. We have just added the two int types to the declaration of the function on the 3rd line.
This way, before encountering the addition() function, the compiler knows that an addition() function exists in our program that will take arguments in it.
Conclusion
This article has discussed too many arguments to function. We have discussed functions briefly, how this error occurs in the C++ program and how to resolve the same.
However, the main thing while resolving this error would be that there should be the same number of arguments wherever the function is defined or declared.
Страницы 1
Чтобы отправить ответ, вы должны войти или зарегистрироваться
#1 10 января 2005г. 11:22:05

- Valera
- Восстановленный участник
- На форуме с 28 декабря 2004г.
- Сообщений: 57
- Спасибо: 0
Тема: Ошибка «too many arguments»
Не понимаю, мучаюсь-мучаюсь, а AutoCAD продолжает писать ошибку «too many arguments».
Всё началось с того, как я подключил диалог и взял из него переменные. Неужели не правильно переменные взяты (dl=t1, dm=t2, ang=t3)?
Вот код лисп с вызовом диалога и дальйшей отрисовкой:
(defun C:proba( / dcl_id dl dm )
(setq dcl_id (load_dialog "vint.dcl")) ; ???????? DCL ?????
(if (not (new_dialog "v1" dcl_id)) ; ???????????????? ??????.
(exit) ;?????, ???? ?????? ?? ????????
; ??????.
)
(action_tile "t1" "(setq "dm" (list $value))")
(action_tile "t2" "(setq "dl" (list $value))")
(action_tile "t3" "(setq "ang" (list $value))")
(setvar "osmode" 0)
(setq x (getpoint))
(setq tvx (car x))
(setq tvy (car (cdr x)))
(setq msw 2)
; ??????????? ??????? ? ????? ?? ?????????? ???????????
(setq dm (* dm msw))
(setq dl (* dl msw))
; ?????? ?????????? ?????
(setq pt22 (list tvx (- tvy (* dm 0.5))))
(setq pt21 (list (- tvx dl) (- tvy (* dm 0.5))))
(setq pt11 (list (- tvx dl) (+ (* dm 0.5) tvy)))
(setq pt12 (list tvx (+ (* dm 0.5) tvy)))
(setq pt111 (list (- tvx dl) (- (+ (* dm 0.5) tvy) (* dm 0.1))))
(setq pt211 (list (- tvx dl) (+ (- tvy (* dm 0.5)) (* dm 0.1))))
(setq pt122 (list tvx (- (+ (* dm 0.5) tvy) (* dm 0.1))))
(setq pt222 (list tvx (+ (- tvy (* dm 0.5)) (* dm 0.1))))
(setq pt01 (list (- tvx (+ dl (* (+ dl (* dm 0.7)) 0.01))) tvy))
(setq pt02 (list (+ tvx (+ (* dm 0.7) (* (+ dl (* dm 0.7)) 0.01))) tvy))
; ??????? ??????? ?????? ?????? ?? ?????
(command "_lweight" "0.25")
(command "_.line" pt111 pt122 "")
(command "rotate" "Last" "" x ang)
(command "_.line" pt211 pt222 "")
(command "rotate" "Last" "" x ang)
; ????????? ???????? ??? ?????, ??????? ????? ?? ?????? ?????????
(command "_.linetype" "_s" "dashdot" "")
(command "_.line" pt01 pt02 "")
(command "rotate" "Last" "" x ang)
(command "_.linetype" "_s" "bylayer" "")
(command "_lweight" "0.5")
; ?????? ?????????? ?????? ?????
(command "_.pline" pt22 pt21 pt11 pt12 "")
(command "rotate" "Last" "" x ang)
;?????? ?????????? ??????
(setq pt31 (list tvx (+ dm tvy)))
(setq pt32 (list (+ tvx (* dm 0.7)) (+ dm tvy)))
(setq pt35 (list (+ tvx (* dm 0.7)) (- tvy dm)))
(setq pt36 (list tvx (- tvy dm)))
(setq pt33 (list (+ tvx (* dm 0.7)) (+ tvy (* dm 0.5))))
(setq pt34 (list (+ tvx (* dm 0.7)) (- tvy (* dm 0.5))))
; ?????? ??????? ?????? ????????????? ?????
(command "_.pline" pt12 pt31 pt32 pt35 pt36 "C" "")
(command "rotate" "Last" "" x ang)
(command "_.line" pt12 pt33 "")
(command "rotate" "Last" "" x ang)
(command "_.line" pt22 pt34 "")
(command "rotate" "Last" "" x ang)
(start_dialog)
(unload_dialog dcl_id)
)
А это код DCL, на всякий случай:
v1 : dialog {label = "??????? ?????????? ????????? ????? ? ?????????????? ????????";
: boxed_row {label = "??????? ????????:";
: edit_box {label = "??????? ??????:";edit_width="2";fixed_width=true;alignment=centered;key="t1";}
: edit_box {label = "?????? ?????:";edit_width="3";fixed_width=true;alignment=centered;key="t2";}
: edit_box {label = "???? ???????? ???????????? ??? ?, ????.:";edit_width="3";fixed_width=true;value="0";alignment=centered;key="t3";}
}
ok_cancel ;
}
#2 Ответ от Евгений Елпанов 10 января 2005г. 12:40:14

- Евгений Елпанов
- Активный участник
- Откуда: Москва
- На форуме с 2 июля 2004г.
- Сообщений: 2,538
- Спасибо: 10
Re: Ошибка «too many arguments»
> Valera
Попробуй вместо:
(action_tile "t1" "(setq "dm" (list $value))") (action_tile "t2" "(setq "dl" (list $value))") (action_tile "t3" "(setq "ang" (list $value))")
Что-то типа:
(action_tile "t1" "(setq dm (list $value))") (action_tile "t2" "(setq dl (list $value))") (action_tile "t3" "(setq ang (list $value))")
Правда не проверял… но должно получиться!
Удачи, если неполучится — спрашивай.
#3 Ответ от Valera 10 января 2005г. 12:55:04

- Valera
- Восстановленный участник
- На форуме с 28 декабря 2004г.
- Сообщений: 57
- Спасибо: 0
Re: Ошибка «too many arguments»
Исправил, но теперь ошибку такого рода выдаёт: «bad argument type: numberp: nil». 🙁
#4 Ответ от Гость 10 января 2005г. 13:02:07
- Гость
- Восстановленный участник
- На форуме с 13 декабря 2003г.
- Сообщений: 105
- Спасибо: 0
Re: Ошибка «too many arguments»
Вот исправил кое-что в начале, децла не трогал,
теперь работает. В выражениях типа:
«(setq dm $value)» аргумент dm не должен быть
в кавычках, да так по мелочам добавил чего.
(defun C:proba( / dcl_id dl dm ang)
(setq dcl_id (load_dialog «vint.dcl»)) ; ???????? DCL ?????
(if (not (new_dialog «v1» dcl_id)) ; ???????????????? ??????.
(exit) ;?????, ???? ?????? ?? ????????
; ??????.
)
(action_tile «cancel» «(done_dialog 0)»)
(action_tile «accept» «(done_dialog 1)»)
(action_tile «t1» «(setq dm $value)»)
(action_tile «t2» «(setq dl $value)»)
(action_tile «t3» «(setq ang $value)»)
(setq done_dlg_val (start_dialog))
(unload_dialog dcl_id)
(if (/= done_dlg_val 1)
(exit)
);if
(setvar «osmode» 0)
(setq x (getpoint))
(setq tvx (car x))
(setq tvy (car (cdr x)))
(setq msw 2)
; ??????????? ??????? ? ????? ?? ?????????? ???????????
(setq dm (* (distof dm) msw))
(setq dl (* (distof dl) msw))
(setq ang (distof ang))
Теперь доводи до ума…
#5 Ответ от Евгений Елпанов 10 января 2005г. 13:02:57

- Евгений Елпанов
- Активный участник
- Откуда: Москва
- На форуме с 2 июля 2004г.
- Сообщений: 2,538
- Спасибо: 10
Re: Ошибка «too many arguments»
Попробуй выложить исходник еще раз…
У меня половина твоей программы выглядит:
?????????????????????????
может смогу сам протестировать.
#6 Ответ от Valera 10 января 2005г. 13:27:37

- Valera
- Восстановленный участник
- На форуме с 28 декабря 2004г.
- Сообщений: 57
- Спасибо: 0
Re: Ошибка «too many arguments»
Для Евгения:
Это DCL-файл диалога (vint.dcl):
v1 : dialog {label = "Задание параметров отрисовки винта с цилиндрической головкой";
: boxed_row {label = "Введите значения:";
: edit_box {label = "Диаметр резьбы:";edit_width="2";fixed_width=true;alignment=centered;key="t1";}
: edit_box {label = "Длинна ножки:";edit_width="3";fixed_width=true;alignment=centered;key="t2";}
: edit_box {label = "Угол поворота относительно оси Х, град.:";edit_width="3";fixed_width=true;value="0";alignment=centered;key="t3";}
}
ok_cancel ;
}
Это сам лисп файл:
(defun C:proba( / dcl_id dl dm )
(setq dcl_id (load_dialog "vint.dcl")) ; Загрузка DCL файла
(if (not (new_dialog "v1" dcl_id)) ; Инициализируется диалог.
(exit) ;Выход, если диалог не работает
; Работа.
)
(action_tile "t1" "(setq dm (list $value))")
(action_tile "t2" "(setq dl (list $value))")
(action_tile "t3" "(setq ang (list $value))")
(setvar "osmode" 0)
(setq x (getpoint))
(setq tvx (car x))
(setq tvy (car (cdr x)))
; Задаём координаты ножки
(setq pt22 (list tvx (- tvy (* dm 0.5))))
(setq pt21 (list (- tvx dl) (- tvy (* dm 0.5))))
(setq pt11 (list (- tvx dl) (+ (* dm 0.5) tvy)))
(setq pt12 (list tvx (+ (* dm 0.5) tvy)))
(setq pt111 (list (- tvx dl) (- (+ (* dm 0.5) tvy) (* dm 0.1))))
(setq pt211 (list (- tvx dl) (+ (- tvy (* dm 0.5)) (* dm 0.1))))
(setq pt122 (list tvx (- (+ (* dm 0.5) tvy) (* dm 0.1))))
(setq pt222 (list tvx (+ (- tvy (* dm 0.5)) (* dm 0.1))))
(setq pt01 (list (- tvx (+ dl (* (+ dl (* dm 0.6)) 0.01))) tvy))
(setq pt02 (list (+ tvx (+ (* dm 0.6) (* (+ dl (* dm 0.6)) 0.01))) tvy))
; Тонкими линиями рисуем резьбу на ножке
(command "_lweight" "0.25")
(command "_.line" pt111 pt122 "")
(command "rotate" "Last" "" x ang)
(command "_.line" pt211 pt222 "")
(command "rotate" "Last" "" x ang)
; Пунктиром проводим ось винта, заменив линию на момент рисования
(command "_.linetype" "_s" "dashdot" "")
(command "_.line" pt01 pt02 "")
(command "rotate" "Last" "" x ang)
(command "_.linetype" "_s" "bylayer" "")
(command "_lweight" "0.5")
; Рисуем полилинией основу ножки
(command "_.pline" pt22 pt21 pt11 pt12 "")
(command "rotate" "Last" "" x ang)
;Задаём координаты шляпки
(setq pt31 (list tvx (+ (* dm 0.75) tvy)))
(setq pt32 (list (+ (* dm 0.6) tvx) (+ (* dm 0.75) tvy)))
(setq pt35 (list (+ (* dm 0.6) tvx) (- tvy (* dm 0.75))))
(setq pt36 (list tvx (- tvy (* dm 0.75))))
(setq pt33 (list (+ tvx (* 0.3 dm)) tvy))
(setq pt34 (list (+ tvx (* 0.6 dm)) tvy))
; Рисуем линиями шляпку винта
(command "_.pline" pt12 pt31 pt32 pt35 pt36 "C" "")
(command "rotate" "Last" "" x ang)
; Толстой линией проводим впадину для отвёртки
(command "_lweight" "0.75")
(command "_.line" pt33 pt34 "")
(command "rotate" "Last" "" x ang)
(command "_lweight" "0.5")
(start_dialog)
(unload_dialog dcl_id)
)
#7 Ответ от Valera 10 января 2005г. 13:38:37

- Valera
- Восстановленный участник
- На форуме с 28 декабря 2004г.
- Сообщений: 57
- Спасибо: 0
Re: Ошибка «too many arguments»
Гость, большое спасибо, всё работает! 🙂
Евгений, исправления гостя работают и тебе большое спасибо.
Я только не понял, что такое «distof»? 🙁
#8 Ответ от Евгений Елпанов 10 января 2005г. 13:45:35

- Евгений Елпанов
- Активный участник
- Откуда: Москва
- На форуме с 2 июля 2004г.
- Сообщений: 2,538
- Спасибо: 10
Re: Ошибка «too many arguments»
Тогда:
(defun C:proba( / dcl_id dl dm )
(setq dcl_id (load_dialog "vint.dcl"))
(if (not (new_dialog "v1" dcl_id))
(exit)
)
(action_tile "t1" "(setq dm (atof $value))")
(action_tile "t2" "(setq dl (atof $value))")
(action_tile "t3" "(setq ang (atof $value))")
(start_dialog)
(unload_dialog dcl_id)
(setvar "osmode" 0)
(setq x (getpoint))
(setq tvx (car x))
(setq tvy (car (cdr x)))
(setq msw 2)
(setq dm (* dm msw))
(setq dl (* dl msw))
(setq pt22 (list tvx (- tvy (* dm 0.5))))
(setq pt21 (list (- tvx dl) (- tvy (* dm 0.5))))
(setq pt11 (list (- tvx dl) (+ (* dm 0.5) tvy)))
(setq pt12 (list tvx (+ (* dm 0.5) tvy)))
(setq pt111 (list (- tvx dl) (- (+ (* dm 0.5) tvy) (* dm 0.1))))
(setq pt211 (list (- tvx dl) (+ (- tvy (* dm 0.5)) (* dm 0.1))))
(setq pt122 (list tvx (- (+ (* dm 0.5) tvy) (* dm 0.1))))
(setq pt222 (list tvx (+ (- tvy (* dm 0.5)) (* dm 0.1))))
(setq pt01 (list (- tvx (+ dl (* (+ dl (* dm 0.7)) 0.01))) tvy))
(setq pt02 (list (+ tvx (+ (* dm 0.7) (* (+ dl (* dm 0.7)) 0.01))) tvy))
(command "_lweight" "0.25")
(command "_.line" pt111 pt122 "")
(command "rotate" "Last" "" x ang)
(command "_.line" pt211 pt222 "")
(command "rotate" "Last" "" x ang)
(command "_.linetype" "_s" "dashdot" "")
(command "_.line" pt01 pt02 "")
(command "rotate" "Last" "" x ang)
(command "_.linetype" "_s" "bylayer" "")
(command "_lweight" "0.5")
(command "_.pline" pt22 pt21 pt11 pt12 "")
(command "rotate" "Last" "" x ang)
(setq pt31 (list tvx (+ dm tvy)))
(setq pt32 (list (+ tvx (* dm 0.7)) (+ dm tvy)))
(setq pt35 (list (+ tvx (* dm 0.7)) (- tvy dm)))
(setq pt36 (list tvx (- tvy dm)))
(setq pt33 (list (+ tvx (* dm 0.7)) (+ tvy (* dm 0.5))))
(setq pt34 (list (+ tvx (* dm 0.7)) (- tvy (* dm 0.5))))
(command "_.pline" pt12 pt31 pt32 pt35 pt36 "C" "")
(command "rotate" "Last" "" x ang)
(command "_.line" pt12 pt33 "")
(command "rotate" "Last" "" x ang)
(command "_.line" pt22 pt34 "")
(command "rotate" "Last" "" x ang)
)
(C:proba)
Вроде -бы рисует какойто болтик 😀
#9 Ответ от Стас 10 января 2005г. 13:53:27

- Стас
- Восстановленный участник
- На форуме с 26 марта 2004г.
- Сообщений: 491
- Спасибо: 0
Re: Ошибка «too many arguments»
distof — преобразование строки, представляющей вещественное значение в одном из форматов линейных единиц, в вещественное число.
#10 Ответ от Valera 10 января 2005г. 14:08:38

- Valera
- Восстановленный участник
- На форуме с 28 декабря 2004г.
- Сообщений: 57
- Спасибо: 0
Re: Ошибка «too many arguments»
Всем большое спасибо!
#11 Ответ от Valera 10 января 2005г. 16:16:38

- Valera
- Восстановленный участник
- На форуме с 28 декабря 2004г.
- Сообщений: 57
- Спасибо: 0
Re: Ошибка «too many arguments»
Ещё такой вопросит по этой же программе (последнее сообщение Евгения):
А вот почему, если я всю программу, начиная с (setvar «osmode» 0) помещаю в ещё одну подрограмму (например, proba2), которую вызываю как (C:proba2) в (proba), то мне выдаёт ошибку «no function definition: C:PROBA2» ?
#12 Ответ от Евгений Елпанов 10 января 2005г. 16:42:24

- Евгений Елпанов
- Активный участник
- Откуда: Москва
- На форуме с 2 июля 2004г.
- Сообщений: 2,538
- Спасибо: 10
Re: Ошибка «too many arguments»
К сожалению, мне сложно догадаться в чем проблемма, но если в ошибке пишется, что не найдена функция, то скорее всего она не загруженна, кстати в моем листинге
(C:proba) — вызов вышеописанной функции…
т.е. твоя задача сначала загрузить все функции, а после их использовать например:
(defun test_1 (/ a1 a2 a3)
(defun test_2 (a1 a2 a3)
(+ a1 a2 a3)
)
(setq a1 1
a2 2
a3 3
)
(test_2 a1 a2 a3)
)
;вызывать (test_1)
#13 Ответ от Valera 10 января 2005г. 17:16:26

- Valera
- Восстановленный участник
- На форуме с 28 декабря 2004г.
- Сообщений: 57
- Спасибо: 0
Re: Ошибка «too many arguments»
Дело в том, что это я хочу применить эту структуру, как продолжение действия radio_button.
Т.е., если одно значение кнопки — одна подпрограммы выполняется, другое — другая.
Но, кстати, ничего не получается 🙁
Я плюнул на это дело и пишу просто:
(if (= bok 1) (progn( ... код отрисовки элемента ?1 ...)) (progn( ... код отрисовки элемента ?2 ...)) );if
Правильна ли такая структура? Потому что мне выдаёт ОШИБКУ «bad argument type: stringp 1». :(((
#14 Ответ от Евгений Елпанов 10 января 2005г. 17:24:43

- Евгений Елпанов
- Активный участник
- Откуда: Москва
- На форуме с 2 июля 2004г.
- Сообщений: 2,538
- Спасибо: 10
Re: Ошибка «too many arguments»
DCL — почти всегда возвращает строку…
т.е. надо:
(= (atoi bok) 1)
или
(equal bok «1»)
#15 Ответ от Valera 10 января 2005г. 17:49:22

- Valera
- Восстановленный участник
- На форуме с 28 декабря 2004г.
- Сообщений: 57
- Спасибо: 0
Re: Ошибка «too many arguments»
Делаю так:
(action_tile "bok" (setq bok 1))
А дальше по тексту, так:
(if (= (atoi bok) 1) (setq x 5) (setq x 10) );if
И выдаёт… «bad argument type: stringp 1» :(((
#16 Ответ от Евгений Елпанов 10 января 2005г. 17:55:38

- Евгений Елпанов
- Активный участник
- Откуда: Москва
- На форуме с 2 июля 2004г.
- Сообщений: 2,538
- Спасибо: 10
Re: Ошибка «too many arguments»
Кажется я уже совсем запутался…
вечер, невнимательный совсем….
(action_tile "bok" (setq bok 1))
Это лисп, а значит bok=1
т.е.
(if (= bok 1) (setq x 5) (setq x 10) )
#17 Ответ от Valera 10 января 2005г. 18:06:23

- Valera
- Восстановленный участник
- На форуме с 28 декабря 2004г.
- Сообщений: 57
- Спасибо: 0
Re: Ошибка «too many arguments»
После разных комбинаций, получилось вот так:
(action_tile "bok" (setq bok "t")) .... (if (equal bok "t") (setq x 5) (setq x 10) )
Но почему-то в любом случае, что bok = «t», что не равен, x=5 🙁
#18 Ответ от Valera 10 января 2005г. 18:43:49

- Valera
- Восстановленный участник
- На форуме с 28 декабря 2004г.
- Сообщений: 57
- Спасибо: 0
Re: Ошибка «too many arguments»
Народ, что же делать-то???! 🙁
Сделал вот так:
(action_tile "bok" (setq bok "b")) (action_tile "tor" (setq tor "t")) .... (if (equal bok "b") (setq x 5) );if (if (equal bok "t") (setq x 10) );if
Так вообще перестали делаться какие-либо действия :(((
Страницы 1
Чтобы отправить ответ, вы должны войти или зарегистрироваться
I’m trying to create a directory and cd into it:
In ~/.bashrc:
function abc() {
appname=$1
appdir="$HOME/code/$appname"
if [ mkdir $appdir -a cd $appdir ]; then
echo Success
else
echo Failed to create and switch directory
fi
}
When I reload bashrc (. ~/.bashrc) I get the error:
bash: [: too many arguments
Failed to create and switch directory
How do I fix this? And what does [: in the error mean?
Ps. Could someone direct me to a «non-cryptic» bash scripting tutorial?
asked May 2, 2011 at 2:16
2
The main error in your script is that the [ command, equivalent to test command, is used to test conditions, like string comparison, existence of files, and so on.
To test the exit status of processes you have to use if without [, so your script could be
if mkdir "$appdir" && cd "$appdir"; then
echo "Success"
else
echo "Failed to create and switch directory"
fi
This is explained in Bash Pitfalls: 9. if [grep foo myfile.
I suggest you go through GrayCat Bash Guide to understand bash.
answered May 2, 2011 at 7:17
enzotibenzotib
90.2k11 gold badges162 silver badges175 bronze badges
2
A prototype could be:
- Create a file in your desktop:
touch newDirectory.sh - Make file executable:
chmod +x newDirectory.sh - To call the script from a terminal in the desktop :
./newDirectory.sh anyName
/
#!/bin/bash
function abc() {
appname=${1}
appdir="$HOME/Desktop/$appname"
if (( mkdir "${appdir}" )) ; then
cd "${appdir}"
echo "Success"
else
echo "Failed to create and switch directory"
fi
}
abc ${1}
Little recommendation: if you are new, do not mess with .bashrc 🙂
enzotib
90.2k11 gold badges162 silver badges175 bronze badges
answered May 2, 2011 at 3:45
9
You are assuming that the output of who | grep jeevansai will be a single line, which is wrong.
++ who
++ grep jeevansai
++ cut -c 32-34
+ ld='31
31 '
This is telling you that the command
ld=`who | grep "jeevansai" | cut -c 32-34`
set the variable ld to «31 31«, rather than to a single number as you were expecting. Later, you try to do math on it …
if [ $ld -gt $cd ]
… expands to …
if [ 31 31 -gt 31 ]
and that’s too many arguments to [.
What you need to do is take the minimum of all the dates that come back from who. Unfortunately, date arithmetic is not easy in shell (note that your program currently ignores the month field altogether). I’d personally reach for Perl or Python instead.
EDIT: For anyone who might be wondering why who prints more than one line of output for a single user: on a modern Unix workstation (OSX included) every shell window you have open will usually get its own entry, because each shell window allocates a pseudoterminal, and the utmp database that who uses, counts each active terminal (pseudo- or otherwise) as its own login. Similarly, screen and tmux will allocate one pseudoterminal for each pane. You might also have a utmp entry for the entire graphical session. All this stuff was designed in the 1970s and hasn’t been changed much since. For example, here’s what it looks like on my Mac when I have two shell windows open:
$ who
zwol console Aug 18 09:59
zwol ttys000 Aug 19 09:49
zwol ttys001 Aug 19 10:35
I am trying to compile a program for school and i get a error message back. «In function … too many arguments to function. What does this mean?
Oct 10 ’06
#1
Banfa
9,065
Expert Mod 8TB
It means you are making a function call and have supplied too many arguments in the place that you call the function. i.e. you have more parameters where you call the function than where it is defined.
For instance this code would generate this error, noting strcpy is defined as
char * strcpy ( char * dest, const char * src );
Expand|Select|Wrap|Line Numbers
- char string[100];
- strcpy(string, «Hello», «World»);
Because strcpy take 2 arguments or parameters but I have supplied 3.
Oct 11 ’06
#2
You defined a function with two parameters as following:
int sum (int, int);
but you call this function with three or more arguments as following:
s = sum(100, 200, 300);
or
s = sum(10, 20, …..);
in this case too many arguments to function error will occure.
Oct 11 ’06
#3
Sign in to post your reply or Sign up for a free account.