I have a variable COUNTRY=”INDIA” and another sets of variables:- INDIA_POPULATION=”5,00,00,000″, CHINA_POPULATION=”6,00,00,000″. In script I am trying to call them using command:- echo ${ ${COUNTRY}_POPULATION } But I am getting bad substitution error. Can someone please tell how to solve it ?? Answer You misplaced a bracket: {$COUNTRY}_POPULATION should be ${COUNTRY}_POPULATION. But even then it would not work as you
Tag: shell
split directory with 10000 files into 2 directories [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 1 year ago. Improve this question I have directory /logos which contains approximately 10000 png images. Can you please suggest some script to make two new
BASH – Create arrays from lines of csv file, where first entry is array name
I’m learning to script in Bash. I have an CSV file, which contains next lines: Need to create arrays from this, where first entry is array name, eg. Here is my script: When I try with csv file, containing only two first string (numbers and colors), code works well. And if i try to with number, colors, custom-1, custom-2, there
Linux Date Function forward/backward time
Is there an option of date function? How do I get LOAD_TEST_START to be 2 minutes forward? How do I get LOAD_TEST_END to be 2 minutes back? Answer This answer helped me and works on the linux-version of date. On macos/FreeBSD one can use
Shell script ‘read’ doesnt work with ‘EOF’
This script below is working, I want to read a value from files svc1.data and used it in syntax. But this script below doesn’t work, it keeps saying : -bash: syntax error near unexpected token `;’ Please help, whats wrong with the 2nd script.. Answer Just close the HEREDOC, like this:
while running this programe i occured one error as ambigous redirect
This is my following bash script And I receive this kind of error: ./l7.sh: line 12: $file_name: ambiguous redirect Here are the full code https://github.com/vats147/public/blob/main/l7.sh And Why I am getting this error? even my syntax is correct. Answer Into the parameter file_name you must assign $1, which will pass to the current file as an input parameter. These are positional
Recode value in the column in unix with awk or sed
In the following file, The values of 6th column for the rows who have values other than 1 or 2 in sixth column should be replaced with -9. How can I do it? old.fam new.fam should be Edit: I used cat old.fam | awk ‘{ if ($6==1 || $6==2) {print $1 ” ” $2 ” ” $3 ” ” $4
converting 4 digit year to 2 digit in shell script
I have file as: Here the 1st column represents dates as YYYYMMDDHH I would like to write the dates as YYMMDDHH. So the desire output is: My script: It is printing Any help please. Thank you. Answer Please don’t kill me for this simple answer, but what about this: You simply cut the first two digits by showing character 3
Ctrl+backtick not working in Linux based terminals [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question
How to show error on console while logging it to both log file and console in bash
I am trying to log messages to both console and a log file in a bash script. I am able to log the stdout message both in console and log file but not a stderr. Below is the script and output. Please help. Script: Log file: Console: I want the below error message to be shown in the console as