•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 425,898 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,932 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 386 | Replies: 2 | Solved
![]() |
•
•
Join Date: Nov 2007
Posts: 122
Reputation:
Rep Power: 1
Solved Threads: 0
I try to simply concat the arguments if they are not the same..... what is wrong with this simple code for concat???
if i run it :
$ ./foo a b c
./foo: a=a b: not found
./foo: a=a c: not found
a
why a=a b: not found??? where this came from???
#!/bin/sh
result=$1
shift
while [ "$#" -ne "0" ]
do
next=$1
if [ $result = $next ]
then
:
else
$result="$result $next"
fi
shift
done
echo "$result"if i run it :
$ ./foo a b c
./foo: a=a b: not found
./foo: a=a c: not found
a
why a=a b: not found??? where this came from???
> $result="$result $next"
Remove the first $ perhaps?
Like your other assignment earlier on.
Remove the first $ perhaps?
Like your other assignment earlier on.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
•
•
Join Date: Apr 2008
Posts: 39
Reputation:
Rep Power: 1
Solved Threads: 8
The above from Salem's post needs to be done to fix your issue.. but you may also want to fix your if statement.
The data in these variables are strings and need to be compared as such.
It probably isn't necessary, but you may want to say:
if [ "$result" = "$next" ]
The data in these variables are strings and need to be compared as such.
It probably isn't necessary, but you may want to say:
if [ "${result}" = "${next}" ]![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- XP not booting - lsass.exe not found (Windows NT / 2000 / XP / 2003)
- Primary HDD 0 not found (Storage)
- bridge.dll cannot be found when booting up, rundll32 not responding when shutting dow (Viruses, Spyware and other Nasties)
- 3 diff. trojans found,please help (Viruses, Spyware and other Nasties)
- Ie Redirected When Ulr Isn't Found, IE redirected when ulr isn't found (Web Browsers)
- Page Can Not Be Found (Networking Hardware Configuration)
- Ureaka!! I found it! Please check this log (Web Browsers)
- printer could not be found (Web Browsers)
Other Threads in the Shell Scripting Forum
- Previous Thread: Need some help with compression / move script
- Next Thread: uniq not working?



Linear Mode