INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Command doesn't work inside a shell script

Command doesn't work inside a shell script

(OP)
Hi,

I tried the following command outside a script on a Linux system and it works perfect. The same command worked inside the script as well, but it suddenly stopped working. I tried different ways but no luck. Please advice!
=============================================
ls /appl/user1/build|grep "20160307112214"

output is build_20160307112214.war

==========================
shell script
==========================
#!/bin/sh
w_tmstamp=`grep tag /appl/user1/deploy/props/env.properties|awk -F"_" '{print $3}'` # the output of this is 20160307112214
war_file=`ls /appl/user1/build|grep $w_tmstamp` # output of this should be build_20160307112214.war but when i do echo $war_file the output is empty.

RE: Command doesn't work inside a shell script

Quote:

The same command worked inside the script as well, but it suddenly stopped working. I tried different ways but no luck. Please advice!

I would advise that you investigate what has changed on the machine in question during the period between it working and it not working.

Any other advice would be simply guesses.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Command doesn't work inside a shell script

(OP)
Thanks Chris.
I found that ^M characters got introduced in env.properties file. Script started working after running dos2unix command against the same property file.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close