Sponsored Content
Top Forums Shell Programming and Scripting Bash script: problem with a function which use colors Post 302989818 by Arnaudh78 on Wednesday 18th of January 2017 02:42:03 PM
Old 01-18-2017
Bash script: problem with a function which use colors

Hello guys Smilie

I've a some issue with a function which use the bash colors in my script.
An example :
Code:
#!/bin/bash

set -x

log_in(){    
    host="srv1"
    remote_files="log/"
    LOG_FILE="logfile"

    green='\033[0;32m'
    red='\033[0;31m'
    none='\033[0m'

    if [[ $1 = "red" ]]; then
    color_in_red=("${red}"$2"${none}")
        echo -e "$color_in_red"
        echo -e "$(date)" "$2" >> "${LOG_FILE}"
    elif [[ $1 = "green" ]]; then
    color_in_green=("${green}"$2"${none}")
        echo -e "$(date)" "$2" >> "${LOG_FILE}"
        echo -e "$color_in_green"
fi
}
log_in red ""$host" The read right is missing on \""$remote_files"\""

The problem is it write good in the logfile but in output it stop write from the first variable, I should be more clear with the output that I had :
Code:
rsync_user@vmtest1:/home/scripts/test$ ./test.sh
+ host=srv1
+ remote_files=log/
+ LOG_FILE=logfile
+ log_in green 'srv1 The read right is missing on "log/"'
+ green='\033[0;32m'
+ red='\033[0;31m'
+ none='\033[0m'
+ [[ green = \r\e\d ]]
+ [[ green = \g\r\e\e\n ]]
+ color_in_green=("${green}"$2"${none}")
++ date
+ echo -e 'Wed Jan 18 17:33:16 CET 2017' 'srv1 The read right is missing on "log/"'
+ echo -e '\033[0;32msrv1'
srv1
rsync_user@vmtest1:/home/scripts/test$

And in the logfile, it works :
Code:
rsync_user@vmtest1:/home/scripts/test$ cat logfile
Wed Jan 18 17:33:16 CET 2017 srv1 The read right is missing on "log/"

Then, all in my console become red or green.. until I type "ll" maybe another commands..

If someone can help me, I would appreciate. Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

colors in BASH, doubt with script

I was trying to see all combinations of foreground and background colors in BASH. This works fine for me, echo -e '\E[37;46m TEXT' but when I tried the below script, the variables i and j do not expand. #!/bin/sh for i in `seq 30 37` # foreground do for j in `seq 40... (4 Replies)
Discussion started by: jaduks
4 Replies

2. UNIX for Dummies Questions & Answers

Easy About Bash Script function

Hi to all, first of all,i am working on MINIX 3 OS. I want to create a bash script file,which will create a list of files(not directories) that have been modified one specific day (i.e today) under my home directory. thank you very much!! :) (8 Replies)
Discussion started by: kostis1904
8 Replies

3. Shell Programming and Scripting

Run function from script over ssh (BASH)

Hi, Is there any cleaver way to run function from the bash scrip over ssh? For example: #!/bin/bash #Function 1 FN1 () { ls -l } #Main run ssh user@host FN1 exit 0 Yeah, I know it will not work, but I'm asking how to make it to work :) I'm suspecting that it would be... (1 Reply)
Discussion started by: columb
1 Replies

4. UNIX for Advanced & Expert Users

AWK sub function curious problem under bash

I need to detect the number of pages in a print job when it is available so I can warn users when they try to print a report much larger than they expected. Sometimes they are trying to print 1000 page reports when they thought they were getting a 10 page report. Under linux I am scanning the... (5 Replies)
Discussion started by: Max Rebo
5 Replies

5. Shell Programming and Scripting

error when call function in bash script

Dear all, Could you please advice as I when call function i found the following error " refills: command not found" note that refills is function name. following also the function and how i call it function refills { echo "formatting refills and telepin" >> $log awk -F,... (20 Replies)
Discussion started by: ahmed.gad
20 Replies

6. Shell Programming and Scripting

bash script function parameters

I have a question about bash script. Can I create a function there that accept parameters like functions in program language? (2 Replies)
Discussion started by: programAngel
2 Replies

7. Shell Programming and Scripting

Help with grep and read function in a BASH Script

I'm putting together a script that will search my mail archives for emails that meet certain criteria and output the files to a text file. I can manually cat that text file and pipe it into sendmail and it will work (i.e. cat /pathtofile/foo.txt | sendmail -t me@company.com) My script sends... (7 Replies)
Discussion started by: binary-ninja
7 Replies

8. Shell Programming and Scripting

Passing parameters to bash script function (or subroutine)

I've found a few posts regarding passing parameters to a function or subroutine, but for some reason when I try to run a command based on part with these parameters it's not working. If I have the function echo the parameters they show correctly so I believe they are being passed right but the... (2 Replies)
Discussion started by: withanh
2 Replies

9. Shell Programming and Scripting

Calling function from another bash script

I would like to call functions from another bash script. How can I do it? Some code More code (11 Replies)
Discussion started by: kristinu
11 Replies

10. Shell Programming and Scripting

Bash function problem

I am trying to figure out why I am having a "problem" with some functions in a bash script I am running. The reason for air quoting is that the functions are working, they are just not displaying anything to screen when called from another function. Here's an example: function Create_Input {... (6 Replies)
Discussion started by: dagamier
6 Replies
ppmdither(1)						      General Commands Manual						      ppmdither(1)

NAME
ppmdither - ordered dither for color images SYNOPSIS
ppmdither [-dim power] [-red shades] [-green shades] [-blue shades] [ppmfile] DESCRIPTION
Reads a portable pixmap as input, and applies dithering to it to reduce the number of colors used down to the specified number of shades for each primary. The default number of shades is red=5, green=9, blue=5, for a total of 225 colors. To convert the image to a binary rgb format suitable for color printers, use -red 2 -green 2 -blue 2. OPTIONS
-dim power The size of the dithering matrix. The dithering matrix is a square whose dimension is a power of 2. power is that power of 2. The default is 4, for a 16 by 16 matrix. -red shades The number of red shades to be used, including black; minimum of 2. -green shades The number of green shades to be used, including black; minimum of 2. -blue shades The number of blue shades to be used, including black; minimum of 2. SEE ALSO
pnmdepth(1), ppmquant(1), ppm(5) AUTHOR
Copyright (C) 1991 by Christos Zoulas. 14 July 1991 ppmdither(1)
All times are GMT -4. The time now is 04:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy