My code worked on a Mac, now it does not work in another computer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting My code worked on a Mac, now it does not work in another computer
# 1  
Old 10-11-2013
My code worked on a Mac, now it does not work in another computer

I guess Mac has default bash. Then I copy my code to another comp and run it...And it gives me an error like "bad substitution"....

How I can change my code??? Never had before this kind of situation. Help please.

Code:
if [ -f "/Users/Natalie/lastserial" ]
then
  n=$(sort /Users/Natalie/lastserial | tail -1)

  fourthoct=${n:0:4}


 thirdoct=${n:4:2}
  thirdoct=${thirdoct#0}
  secondoct=${n:6:2}
  secondoct=${secondoct#0}
  firstoct=${n:8:2}
  firstoct=${firstoct#0}

  if [ $((++firstoct)) -eq 100 ]
  then
      firstoct=0
      if [ $((++secondoct)) -eq 32 ]
      then
          secondoct=0
          if [ $((++thirdoct)) -eq 13 ]
          then
              thirdoct=0
              ((++fourthoct))
          fi
      fi
  fi

  printf  "%04d%02d%02d%02d\n" $fourthoct $thirdoct $secondoct $firstoct > '/Users/Natalie/lastserial'
else
  echo ` date +%Y%m%d`"00" >'/Users/Natalie/lastserial'
fi

# 2  
Old 10-11-2013
What OS is the other computer?
How do you call/execute the script?
# 3  
Old 10-11-2013
At the top of you script, include this line (right beneath the shebang line):
Code:
set -x

That turns debug mode on. When you run your script from the command line, it will execute step by step and stop where it finds an error. That will give you a clue as to what's wrong.
Do not hesitate to get back to us with the error that you find.
# 4  
Old 10-11-2013
Quote:
Originally Posted by gacanepa
At the top of you script, include this line (right beneath the shebang line):
Code:
set -x

That turns debug mode on. When you run your script from the command line, it will execute step by step and stop where it finds an error. That will give you a clue as to what's wrong.
Do not hesitate to get back to us with the error that you find.
+ [ -f /Users/Natalie/lastserial ]
+ sort /Users/Natalie/lastserial
+ tail -1
+ n=2013101001
makedns: 10: makedns: Bad substitution

---------- Post updated at 03:30 PM ---------- Previous update was at 03:29 PM ----------

Quote:
Originally Posted by Scrutinizer
What OS is the other computer?
How do you call/execute the script?
Its windows....I use sh
# 5  
Old 10-11-2013
For windows you would want to use: Batch file - Wikipedia, the free encyclopedia
However, you could use Bash (Unix shell) - Wikipedia, the free encyclopedia for Windows, if you had installed Cygwin.

Additionaly to this weird post, i mean...
You use SH on a WinOS on a Mac... hmm....

The topic, subject, content (lost in translation) of your scripts, seems VERY MUCH similar to: https://www.unix.com/shell-programmin...rementing.html
As in: The same homework, diffrent approaches.

Hth
# 6  
Old 10-11-2013
Quote:
Originally Posted by Natalie
[..]
Its windows....I use sh
Is that cygwin? Try using bash instead of sh

Last edited by Scrutinizer; 10-11-2013 at 10:55 PM..
# 7  
Old 10-11-2013
Cant say for sure actualy...
Been told so, though.

She wrote bash, as far as i reckognize...
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Rebuilding computer tomorrow at work

I'm rebuilding my primary computer at work tomorrow. Currently, it has Windows 7. I would like to replace the main system with either Linux or Unix, although I would like to be able to run a fully operational Windows as a VM within that. Any recommendations on which Linux or Unix to go with? I'm... (6 Replies)
Discussion started by: Sean_
6 Replies

2. UNIX for Dummies Questions & Answers

Code not worked,as expected

Hi All, OS :- HPUX.. I have a following code, which I wrote to meet date and time condition. The below code refuse to work for some reason, I still don't have any idea, why ? the below code, should exit out, if the day happens to be sat and time greater the 04:00 pm. I am bit surprised, that... (2 Replies)
Discussion started by: alok.behria
2 Replies

3. What is on Your Mind?

Volunteer Work When Out of a Computer Job?

I need opinion from other ! I finished high school for computer technician few months ago and now I can not find a job because I do not have any experience with servers , I know basic staff about Linux and Unix and Windows better (used three 4 years) (this is way I registered here at... (3 Replies)
Discussion started by: solaris_user
3 Replies

4. What is on Your Mind?

If possible, would you consider buying OS X for a non Mac computer?

Title says it all. I am doing a little research for a blog I want to write up on my website about different OS platforms. One thing that I am trying to figure out, is that would it appeal to people to load OS X on their PC, and would they be willing to pay for it? If so, would you even... (17 Replies)
Discussion started by: tlarkin
17 Replies

5. UNIX for Dummies Questions & Answers

why doesn't this script work on my home computer?

Now it could be as simple as at work I use tsch, and at home it is bash. Warning, first post and I am a complete newbie to unix. At work, I use a simple script for updating a window when I am watching to see how a render is doing... while 1 echo --------------------------- echo ls -lrth... (1 Reply)
Discussion started by: iStealMusic
1 Replies
Login or Register to Ask a Question