LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-15-2013, 02:05 AM   #1
harpal singh
LQ Newbie
 
Registered: Jan 2013
Posts: 1

Rep: Reputation: Disabled
Angry Script is working fine but getting Command not found error


Hi ,

I am using below script to do some work. But even though script is working fine but while executing it i am getting command not found error.

Here is the script :-



#!/bin/sh
Names="name.txt"

###main#####
for LINE in `cat ${Names}`
do
Name=`echo $LINE |awk -F'|' '{print $1}'`
`<some Command>:$Name`
echo $Name is unlocked
done
echo "Unlocking is done"

NOte:- its reading Names one by one from file and executing some commmnad. Functionality is working fine but i am not sure whey
"./script.sh: line 11: Unlocked: command not found" is coming.
 
Old 01-15-2013, 03:15 AM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Try placing your variables inside double quotes e.g. "$VAR". Also if contents of name.txt has to be processed line by line, use "while read" instead:
Code:
while read LINE; do
     Name=`echo "$LINE" | awk -F'|' '{print $1}'`
     ...
done < "$Names"
If it's necessary to keep leading and trailing spaces, or if IFS is expected to be altered, use IFS='' before read:
Code:
while IFS='' read LINE; do
Note that adding extra command like that could slow down loop speed by 50% though not really significant.
 
1 members found this post helpful.
Old 01-15-2013, 04:49 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Please use [code] and [/code] tags
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mercurial Hg push command not working - Error: No changes found sangal_ak04 Linux - Software 4 01-10-2013 08:30 PM
[SOLVED] $'\r': command not found script error Reignfire Linux - Newbie 4 12-10-2012 09:23 AM
[SOLVED] command not found error when running my bash script thras0 Programming 3 07-28-2012 02:43 PM
command not found error while executing a shell script SurbhiJain Linux - Newbie 15 07-26-2010 09:18 AM
'command not found' but works fine anyway HickorySlim Linux - General 11 08-03-2002 06:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration