Sponsored Content
Full Discussion: Array problem in Bash Script
Top Forums UNIX for Beginners Questions & Answers Array problem in Bash Script Post 302983763 by cogiz on Sunday 16th of October 2016 05:43:46 PM
Old 10-16-2016
Linux Array problem in Bash Script

I am trying to write a Bash Script using a couple of arrays. I need to perform a countdown of sorts on an array done once daily, but each day would start with the numbers from the previous day. This is what I'm starting with :

Code:
#!/bin/bash

days=(9 8 7 6 5)

for (( i = 0 ; i < ${#days[@]} ; i++ ))
  do (( days[$i]=${days[$i]} - 1 )) 
  done

This leaves me with this :
Code:
$ 8 7 6 5 4

How do I start with days=(8 7 6 5 4) the next time the script is run instead of days=(9 8 7 6 5)?

I am using Linux Mint 18 (Cinnamon) and the latest version of Bash

Thank You in advance for any and all suggestions.
Cogiz

Last edited by Scrutinizer; 10-16-2016 at 11:15 PM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

bash array problem

hi friends., i have two files yy.dat and mm.dat containing 110 elements in each if i read them into variables it is just showing only 4 elements instead of 110 elements My script is like this ################################## /bin/bash declare -a yy=(`cat yy.dat`) echo "No of values in... (1 Reply)
Discussion started by: yagnesh
1 Replies

2. Shell Programming and Scripting

bash Script: Issue with iterating Directory and store into array

Hi all, I am working on a backup based script, in which it enters to a directory and check the sub-directories and copy the names into an array. cd $CPFs k=0 for i in * do if then ARRs="$i" k=$(($k+1)) #echo "$i" ... (19 Replies)
Discussion started by: canishk
19 Replies

3. Emergency UNIX and Linux Support

Problem with Array in Script

Below is my script. This script is getting an error code such as this one. fileListener.bat: entityArray=craig.uss@pnc.com: not found craig.uss@pnc.com fileListener.bat: entityArray=duns_noncusts.txt: not found duns_noncusts.txt fileListener.bat: entityArray=duns_misc.cpy: not found... (4 Replies)
Discussion started by: mkjp
4 Replies

4. Shell Programming and Scripting

problem access array outside of loop in bash

Below is a test script I was trying to use so that I could understand why the logic was not working in a larger script. While accessing and printing array data inside the while loop, everything is fine. Outside the loop, i guess everything is null?? The for loop that is meant to cycle... (4 Replies)
Discussion started by: adlmostwanted
4 Replies

5. Shell Programming and Scripting

Bash 3.2 - Array / Regex - IF 3rd member in array ends in 5 digits then do somthing...

Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help. pesudo code if == ENDSINFIVEINTS ]]; then do... (4 Replies)
Discussion started by: briandanielz
4 Replies

6. Shell Programming and Scripting

Bash shell script undefined array item value question

Hello, I'm new here. I test these expressions's value in my script : (in centOS 6 ) #!/bin/bash array='something' echo "############" echo ${array} echo ${array} echo ${array} echo "############" The output result is : ################# something something #################... (5 Replies)
Discussion started by: lingjing
5 Replies

7. Shell Programming and Scripting

Bash arrays: rebin/interpolate smaller array to large array

hello, i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N. for case 1, I want to stretch N to fit M arrayHuge H = (... (2 Replies)
Discussion started by: f77hack
2 Replies

8. UNIX for Beginners Questions & Answers

Scanning array for partial elements in Bash Script

Example of problem: computerhand=(6H 2C JC QS 9D 3H 8H 4D) topcard=6D How do you search ${computerhand} for all elements containing either a "6" or a "D" then save the output to a file? This is a part of a Terminal game of Crazy 8's that I'm attempting to write in Bash. Any... (2 Replies)
Discussion started by: cogiz
2 Replies

9. Shell Programming and Scripting

Array compare bash script

Hello, i have a script that should compare between ${ARRAY} that contains all fstab record like this : >>echo ${ARRAY} / /boot between all mountpoints in my df that is stord in ${ARRAY2} >>echo ${ARRAY2} / /boot /dev/shm /var/spool/asterisk/monitor now i have this loop: for i in... (6 Replies)
Discussion started by: batchenr
6 Replies

10. UNIX for Beginners Questions & Answers

Need a Bash script for iterating thru an array and running a command

Hi , I am a total beginner so bear with me. I have the below code which works . I need to extend it by iterating thru the array arr and executing a command in each loop. some thing on the lines of below. I need to run this in a Jenkins script , so I would need below bash script to run... (6 Replies)
Discussion started by: SVRao19056
6 Replies
lchage(8)						      System Manager's Manual							 lchage(8)

NAME
lchage - Display or change user password policy SYNOPSIS
lchage [OPTION]... user DESCRIPTION
Displays or allows changing password policy of user. OPTIONS
-d, --date=days Set the date of last password change to days after Jan 1 1970. -E, --expire=days Set the account expiration date to days after Jan 1 1970. Set days to -1 to disable account expiration. -i, --interactive Ask all questions when connecting to the user database, even if default answers are set up in libuser configuration. -I, --inactive=days Disable the account after days after password expires (after the user user is required to change the password). -l, --list Only list current user's policy and make no changes. -m, --mindays=days Require at least days days between password changes. Set days to 0 to disable this checking. -M, --maxdays=days Require changing the password after days since last password change. Set days to 99999 to disable this checking. -W, --warndays=days Start warning the user days before password expires (before the user is required to change the password). EXIT STATUS
The exit status is 0 on success, nonzero on error. libuser Jan 12 2005 lchage(8)
All times are GMT -4. The time now is 07:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy