小编El *_*opo的帖子

改变辫子的颜色

有什么方法可以改变马尾辫的特定颜色吗?

例如,将特定文本标记为红色?

例如 :

#!/bin/bash
window=$(stty -a | tr \; \\012 |egrep 'rows|columns' | cut '-d ' -f3)
RED="red"
GREEN="green"


OPTION=$(whiptail --menu "\n\n\n\n\n\n\n\n" --title  "menu" --nocancel $window 20 \
"1" "COLOUR IS $RED" \
"2" "COLOUR IS $GREEN" 3>&1 1>&2 2>&3)
Run Code Online (Sandbox Code Playgroud)

如何为$ RED和$ GREEN上色?

linux bash colors whiptail

3
推荐指数
1
解决办法
2409
查看次数

在bash脚本文件中记录

我有一个很大的脚本(函数包含大约4000行代码)。这是它的一部分:

#!/bin/bash 


. ./functions > /dev/null 2>&1

some_function(){

while true
do

CHOICE=$(whiptail --menu "\n\n\n\n\n\n\n\n" --title "Tools" --nocancel $window 20 \
"1" "Option1" \
"2" "Option2" \
"3" "Option3" 3>&1 1>&2 2>&3)


case $CHOICE in

    1)echo $1 $2 $3;;
    2)echo $2 $1 $3;;                                       
    3)echo $3 $2 $1;;

esac
done
}



while true; do 
arr=()
for ((n=1; n<=$node_num; n++))
        do
        node+=($n NODE$n)
done


OPTION=$(whiptail --menu "\n\n\n\nPlease choose:\n\n\n" --title "tools" $window 20 "${node[@]}" \

case $OPTION in

        1) some_function 1 2 3 ;; …
Run Code Online (Sandbox Code Playgroud)

linux bash shell logging

2
推荐指数
1
解决办法
4039
查看次数

bash /循环后变量值为空

我是新手bash并尝试一个简单的循环,但我的变量的值在它之后丢失,我无法理解为什么 - 我看了几个类似的问题,但它们都与while循环的子shell执行有关.我不是在做但仍面临问题 - 有人可以解释我的错误在哪里?

#!/bin/bash

check_ss ()    
{    

command_list | awk '{print $1 $9}' > ss.out    

 for i in {1..8}    
            do grep -Pa "\x3$i" ss.out > ss$i.out   
                    if grep -w "NotStarted" ss$i.out   
                            then   
                                   ss$i=0   
                            else    
                                ss$i=1    
                    fi   
done   
}   
check_ss      
echo $ss1     
echo $ss2    
echo $ss3    
echo $ss4    
Run Code Online (Sandbox Code Playgroud)

我正在执行这个:

[root@lubo ~]# ./ss.sh    
./ss.sh: line 21: ss1=1: command not found     
./ss.sh: line 21: ss2=1: command not found      
./ss.sh: line 21: ss3=1: command not found      
./ss.sh: line 21: ss4=1: command not …
Run Code Online (Sandbox Code Playgroud)

variables bash loops

1
推荐指数
1
解决办法
648
查看次数

Linux中最快的C代码以递归方式计算目录(无文件)

以下C代码将列出文件和目录的数量,并且比linux find命令快4倍。我只需要文件夹的数量,对文件数量甚至列出它们都不感兴趣。有没有一种方法可以优化以下代码并使之更高效?

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>

void listdir(char *path, size_t size) {
    DIR *dir;
    struct dirent *entry;
    size_t len = strlen(path);

    if (!(dir = opendir(path))) {
        fprintf(stderr, "path not found: %s: %s\n",
                path, strerror(errno));
        return;
    }

    puts(path);
    while ((entry = readdir(dir)) != NULL) {
        char *name = entry->d_name;
        if (entry->d_type == DT_DIR) {
            if (!strcmp(name, ".") || !strcmp(name, ".."))
                continue;
            if (len + strlen(name) + 2 > size) {
                fprintf(stderr, "path too …
Run Code Online (Sandbox Code Playgroud)

c linux directory recursion counting

-4
推荐指数
1
解决办法
110
查看次数

标签 统计

bash ×3

linux ×3

c ×1

colors ×1

counting ×1

directory ×1

logging ×1

loops ×1

recursion ×1

shell ×1

variables ×1

whiptail ×1