ERP - MES Interface - several function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ERP - MES Interface - several function
# 1  
Old 03-02-2013
Bug ERP - MES Interface - several function

Hi all,

I am a rookie regarding shell script programming, YET!! :-)

Hence, I have choosen a problem from my bad side of life (my job) and I wil try to solve it by using a shell script and get knowledge concerning shell script programming.

Question: As you can see I have already figured out how to use a function, variables, different standard funtions (if, loops,etc). But I struggeld by using the printf function in order to add blanks to string. If the string which I pass into the function is longer than 40 digits then the printf function has to shorten string to 40 digits. This function works perfectly but if the string is shorter than 40 digits then the printf function has to add blanks until the string has a lenght of 40 digits but this part of my shell script doesn't work Smilie !!! The function adds only ONE blank

Code:
#!/bin/bash
fkt_auffuellen()
{
case $1 in
 "C")
   if [ ${#2} -eq $3 ]; then
    value=$2
   elif [ ${#2} -lt $3 ]; then 
    value="$(printf "%-$3s" $2)"
   else
    value="$(printf "%.$3s" $2)"
fi;; 
 "N")
;;
 "D")
;;
esac
}
vorg_nr_t=C
vorg_nr="AUFTRAG005-010010"
vorg_nr_l=40
fkt_auffuellen $vorg_nr_t $vorg_nr $vorg_nr_l
echo $value

if anyone can give an advice it would be great!!!!

Thanks in advance and cold but sunny greetings form BERLIN Area!

Noobie1995

P.S.: I am so sorry for my english it has been a while..........
# 2  
Old 03-02-2013
Hi, try:
Code:
echo "$value"

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 03-02-2013
Great, it works but you can imagine it brings me to some more questions:
1. why I have to pass the value variable into ""?
2. I have extended the code (green lines) and the code brings the previous[incorrect result]?

Code:
#!/bin/bash
fkt_auffuellen()
{
case $1 in
 "C")
   if [ ${#2} -eq $3 ]; then
    value=$2
   elif [ ${#2} -lt $3 ]; then 
    value="$(printf "%-$3s" $2)"
   else
    value="$(printf "%.$3s" $2)"
fi;; 
 "N")
;;
 "D")
;;
esac
}
vorg_nr_t=C
vorg_nr="AUFTRAG005-010010"
vorg_nr_l=40
fkt_auffuellen $vorg_nr_t $vorg_nr $vorg_nr_l
vorg_nr="$value"
echo $vorg_nr

# 4  
Old 03-02-2013
Try:
Code:
vorg_nr=$value
echo "$vorg_nr"

You do not need the double quotes with the assignment, but you do need them with the echo statement, otherwise the content of the variable will be interpreted by the shell and split into fields using IFS (the input field selector)..
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 03-02-2013
And the same rule applies here:
Code:
value=$(printf "%-$3s" "$2")

value= is an assignment, no need for quotes.
$2 is an argument (of the printf command), to be quoted.

---------- Post updated at 12:37 PM ---------- Previous update was at 12:27 PM ----------

The exception proves the rule:
Code:
if [ ${#2} -eq "$3" ]; then

These are arguments to the [ ] (test) function.
The $3 should be quoted if can be tampered with, e.g. became a * or 1 2.
Not needed, if your script guarantees a number.
The ${#2} is always a number.
This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 03-02-2013
Thanks all,

the comments have been very helpful and I can see clearly the problem.

Thanks and have a nice weekend

BR,

Noobie1995
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. War Stories

Project - ERP-MES Interface

Hi all, that's my personal "war story" and probably a beginning of a never ending love story. It is roughly 8 weeks ago, I've got a training for a new ERP system. In front of the training my boss mentioned it based on a unix. Great, I have been always interested in but I don't know why I... (2 Replies)
Discussion started by: Noobie1995
2 Replies

2. IP Networking

Need a bridge from an ethernet interface to a serial interface

This is my situation DOS pc serial cable (sl0) Linux Pc eth1 192.168.0.10 <-------------------->192.168.0.2 <------------>192.168.0.1 (router) I connected the linux pc and the dos pc with a SLIP (serial line internet protocol), so they can communicate in the sl0 interface. ... (3 Replies)
Discussion started by: mghis
3 Replies

3. UNIX and Linux Applications

CK-ERP (Open Source Edu / ERP / CRM / MRP) v.0.30.1 released

Hi, folks, A new release, v.0.30.1, of CK-ERP, has been posted, at SourceForge.Net, sourceforge.net/projects/ck-erp . New features comprise seven new modules (ck-teacher, ck-counsellor, ck-student, ck-applicant, ck-family, ck-registrar, ck-eduadmin) for deployment within educational... (0 Replies)
Discussion started by: chiukay
0 Replies

4. SCO

Change SCO - GUI or Desktop interface to DOS based interface

Hi all I have installed a demo version of SCO OpenServer 5.0.2, I finally found it is Desktop Interface, I would like to know how to change its interface to dos based interface? If you have any ideas, please tell me then. Thank you (2 Replies)
Discussion started by: TinhNhi
2 Replies

5. Solaris

Command line Interface or GUI Interface not shown on solaris

Dear all, I am a newbie in solaris and I need your advice. I have a Solaris version 5.9 installed on Sunfire V240. I am able to ssh the machine from putty remotely. My problem is that I cannot see the display from KVM switch I have connected to it. I need also to be able to see the GUI... (2 Replies)
Discussion started by: mbouster
2 Replies

6. Programming

Compilation problem with Posix Mes Q

Hi #include "training.h" #include <mqueue.h> // for posix mqs int main(int argc,char *argv) { int opt,flag; mqd_t msq; // msg q type flag=O_RDWR|O_CREAT; while((opt =getopt(argc,argv,"e")) != -1) { switch(opt) { case 'e': ... (4 Replies)
Discussion started by: kumaran_5555
4 Replies

7. UNIX for Dummies Questions & Answers

Command 'rm -f -r "0yfOYy-0008Nq-2j-32233-K"' failed with return code 1 and error mes

I would like to know what means this error and how to fix it Command 'rm -f -r "0yfOYy-0008Nq-2j-32233-K"' failed with return code 1 and error message Thank you (3 Replies)
Discussion started by: linuxbee
3 Replies

8. UNIX and Linux Applications

Linux based Open Source ERP System - CK-ERP

Hi, folks, I have developed CK-ERP, which is an open source accounting / MRP / ERP / CRM system that runs on top of multiple middlewares. It provides accounting and back office functionalities to SMEs and utilizes the underlying middleware to administer accounts/groups. Details about and... (0 Replies)
Discussion started by: chiukay
0 Replies
Login or Register to Ask a Question