473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Small project, big headache. 7 segment display in bash

I've never been very good at bash, but usually I get things done on the rare occasion that I need to. This challenge however, is beyond me.

Expand|Select|Wrap|Line Numbers
  1. #!/bin/bash
  2.  
  3. farr0=("#####" "    #" "#####" "#####" "#   #" "#####" "#    " "#####" "#####" "#####" "    #" "     ")
  4. farr1=("#   #" "    #" "    #" "    #" "#   #" "#    " "#    " "    #" "#   #" "#   #" "   # " "  #  ")
  5. farr2=("#   #" "    #" "#####" "#####" "#####" "#####" "#####" "    #" "#####" "#####" "  #  " "     ")
  6. farr3=("#   #" "    #" "#    " "    #" "    #" "    #" "#   #" "    #" "#   #" "    #" " #   " "  #  ")
  7. farr4=("#####" "    #" "#####" "#####" "    #" "#####" "#####" "    #" "#####" "    #" "#    " "     ")
  8.  
  9. function print_datetime {
  10.      datetime=`date '+%Y%m%d%H%M%S'`
  11.  
  12.      for i in {0..4}
  13.         do
  14.             # What I'd like: (example for year only)
  15.             # echo -n ${farr{$i}[$datetime[0]]}
  16.             # echo -n ${farr{$i}[$datetime[1]]}
  17.             # echo -n ${farr{$i}[$datetime[2]]}
  18.             # echo -n ${farr{$i}[$datetime[3]]}
  19.  
  20.     done
  21. }
  22. print_datetime
In this case the desired output would be:
Expand|Select|Wrap|Line Numbers
  1. ##### #####     # #####
  2.     # #   #     # #    
  3. ##### #   #     # #####
  4. #     #   #     #     #
  5. ##### #####     # #####
I have tried a number of approached, but none of them have worked out, all of them have been overly complex, and think the reason basically is that I haven't the slightest clue what I'm doing, and am taking the wrong approach.

Don't get me wrong, I can do this, and have done so using both awk and C, so regardless I have a solution, but I would really like to know where I'm going wrong.

I know I haven't provided much in term of example code, but the reason is simply that nothing really works. It's not just a matter of syntax error or similar, it's me doing something fundamentally wrong.


Anyway, if you have something to add, I'd like to hear it. I know it isn't really a question as such, but here goes anyway.


Best regards.
Jun 29 '15 #1
3 4989
I know this is an old question but I wanted to take a shot at it. Here is what I came up with:
Expand|Select|Wrap|Line Numbers
  1. #!/bin/bash
  2. farr0=("##### " "    # " "##### " "##### " "#   # " "##### " "#     " "##### " "##### " "##### " "    # " "     ")
  3. farr1=("#   # " "    # " "    # " "    # " "#   # " "#     " "#     " "    # " "#   # " "#   # " "   #  " "  #  ")
  4. farr2=("#   # " "    # " "##### " "##### " "##### " "##### " "##### " "    # " "##### " "##### " "  #   " "     ")
  5. farr3=("#   # " "    # " "#     " "    # " "    # " "    # " "#   # " "    # " "#   # " "    # " " #    " "  #  ")
  6. farr4=("##### " "    # " "##### " "##### " "    # " "##### " "##### " "    # " "##### " "    # " "#     " "     ")
  7.  
  8. function print_datetime {
  9.      datetime=`date '+%Y%m%d%H%M%S'`
  10.  
  11.      for i in {0..4}
  12.         do
  13.             # What I'd like: (example for year only)
  14.             tmp=farr${i}'['${datetime:0:1}']'
  15.             echo -n "${!tmp}"
  16.             tmp=farr${i}'['${datetime:1:1}']'
  17.             echo -n "${!tmp}"
  18.             tmp=farr${i}'['${datetime:2:1}']'
  19.             echo -n "${!tmp}"
  20.             tmp=farr${i}'['${datetime:3:1}']'
  21.             echo "${!tmp}"
  22.         done
  23. }
  24. print_datetime
  25.  
I couldn't figure out how to do it without a temporary variable. Here is the output:
Expand|Select|Wrap|Line Numbers
  1. ##### #####     # #
  2.     # #   #     # #
  3. ##### #   #     # #####
  4. #     #   #     # #   #
  5. ##### #####     # #####
Feb 29 '16 #2
Oralloy
988 Expert 512MB
Zacariaz,

Take a look at the "eval" command built in to the bash shell.

Secondly, you left out an enclosing pair of braces on the "datetime" array

try:
Expand|Select|Wrap|Line Numbers
  1. eval echo -n "\${farr$i[${datetime:0:1}]}"
to assign to an intermediate variable, use:
Expand|Select|Wrap|Line Numbers
  1. eval intVariable="\${farr$i[${datetime:0:1}]}"
Luck!
Oralloy
Sep 1 '16 #3
Oralloy
988 Expert 512MB
Zacariaz,

I do hope that this isn't one of your homework problems. Unfortunately our policy is that we don't do peoples' homework for them, although we will give advice to help, so you learn how to do things well.

I think that use of the bash "eval" command is sufficiently obscure that you haven't met it yet.

If I just stepped on my own toes, please forgive.

Cheers!
Oralloy
Sep 1 '16 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Thomas Weholt \( PRIVAT \) | last post by:
I've got a rather small project, small in the sense that there's not a lot of different tables needed in the database/storage-system, but there will be alot of data and the clients must be able to...
0
by: Glenn Wilson | last post by:
I have been given a small project.... I have to be able to connect to several time servers and provide reports on the differance between these systems. At the moment I have a list of 3 servers......
0
by: Nitin123456789 | last post by:
hi I am naive user to Vb 6.0. I have 1 small project to do. There are 4 folders in which there are 500 files in first folder and other three folders may or may not contain 500 files So aim...
3
by: Aussie Rules | last post by:
Hi, I am unable to build a project, and can not figure out why. Is there a log file or some way of seeing what is going on. I get 'visual studio is busy.....' message if i try to click or do...
0
by: adam | last post by:
We need an ASP.NET/Ajax expert to help us finish a small application. This seemed to be a good place for posting this, since the ASP.NET Ajax framework is quite new and it has been difficult to...
2
by: adminravi | last post by:
Hi, I have just learnt visual C++ 6.0 and I m comfortable with programming. I want to know if there are any API's that I can use to build some project. I want to work on a small project to...
2
by: AEB | last post by:
Hello, my supervisor has requested that I write a program to display 2D waves in 3D using Python. Basically I have a time series file that has the heights of the wave over time steps, and I want...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.