Я проверил ваш код, я думаю, что MethodeUsingGetImagesSourceFileName
и MethodeUsingReverseArray
негибки. Если вы просто хотите обработать строковый массив, вы можете создать ListExtension
с List<string>
для вашего массива изображений.
public static class ListExtension
{
public static void InitializeImageArray(this List<string> items, int start,int end)
{
for (int i = start; i <= end; i++)
{
items.Add($"images{i}.png");
}
}
public static string GetImageFileNameWithIndex(this List<string> items, int index)
{
return items[index];
}
}
Использование
private List<string> _imgImageitems = new List<string>();
private List<string> _btnImageitems = new List<string>();
private void InitializeImages()
{
_imgImageitems.InitializeImageArray(1, 5);
_btnImageitems.InitializeImageArray(6, 10);
}
Получить имя файла изображения с индексом
string image = _imgImageitems.GetImageFileNameWithIndex(1);
Обратный список [1114 ]
_imgImageitems.Reverse();
Попробуйте:
alias lock='gnome-screensaver; gnome-screensaver-command --lock'
или
lock() {
gnome-screensaver
gnome-screensaver-command --lock
}
в вашем .bashrc
Второе решение позволяет вам использовать аргументы .
Разве это не работает?
alias whatever='gnome-screensaver ; gnome-screensaver-command --lock'
Это будет запускать 2 команды одну за другой:
alias lock='gnome-screensaver ; gnome-screensaver-command --lock'
Так используйте точку с запятой:
alias lock='gnome-screensaver; gnome-screen-saver-command --lock'
Это не очень хорошо работает, если вы хотите предоставить аргументы для первой команды. В качестве альтернативы, создайте тривиальный скрипт в вашем каталоге $ HOME / bin.
Aliases are meant for aliasing command names. Anything beyond that should be done with functions.
alias ll='ls -l' # The ll command is an alias for ls -l
Aliases are names that are still associated with the original name. ll
is just a slightly specific kind of ls
.
d() {
if exists colordiff; then
colordiff -ur "$@"
elif exists diff; then
diff -ur "$@"
elif exists comm; then
comm -3 "$1" "$2"
fi | less
}
A function is a new command that has internal logic. It isn't simply a rename of another command. It does internal operations.
Technically, aliases in the Bash shell language are so limited in capabilities that they are extremely ill suited for anything that involves more than a single command. Use them for making a small mutation of a single command, nothing more.
Since the intention is to create a new command that performs an operation which internally will resolve in other commands, the only correct answer is to use a function here:
lock() {
gnome-screensaver
gnome-screensaver-command --lock
}
Usage of aliases in a scenario like this runs into a lot of issues. Contrary to functions, which are executed as commands, aliases are expanded into the current command, which will lead to very unexpected issues when combining this alias "command" with other commands. They also don't work in scripts.
Другие ответы адекватно отвечают на вопрос, но ваш пример выглядит так, как будто вторая команда зависит от успешного выхода первой команды , Возможно, вы захотите попробовать оценку короткого замыкания в своем псевдониме:
alias lock='gnome-screensaver && gnome-screensaver-command --lock'
Теперь вторая команда даже не будет предпринята, пока первая команда не будет успешной. Более подробное описание оценки короткого замыкания описано в этом вопросе SO .