I'm new to shell scripting and trying to concatenate two Strings to create a filepath like string but I'm getting an unexpected result.
here is my code for 'runToneUserLoad.sh':
I run this script as :
I'm getting the following result for
Script Dir:/users/apps/vbolt/tmsmari/toneUserLoadUtility
but, for some reason
is resulting in : /installedUtility/vbolt/tmsmari/toneUserLoadUtility
I was expecting this value to be: /users/apps/vbolt/tmsmari/toneUserLoadUtility/installedUtility
Could you please tell why I am getting this result or I'm missing very basics of string concatenation in shell script?
Okay. The script itself looks sound in Posix Shell. Please mention what Shell you are using in the next post! Also, it always helps to know what Operating System and version you have.
I think your script contains some funny characters (like carriage-returns from a Microsoft Windows editor?).
Please post the output from the following command which is designed to make control characters visible:
(Or whatever your script is called - the post is inconsistent). Disregard: O/P has fixed the post.
While I remember.
Quote:
script_dir="$(dirname $0)"
There will be no trailing solidus on this output. Bear this in mind when the main problem in the script is fixed.
You can prove my theory about bad characters in the script if you execute the script as:
Good guess on my part!
The script is riddled with carriage-return characters (showing as \r). These usually come from using Microsoft editors (such as Notepad).
A unix text file has every line terminated with a line-feed character.
A MSDOS text file has every line terminated with two characters carriage-return then line-feed. This is a left-over from one of the greatest MSDOS mistakes.
To fix your script we can use the unix "tr" command to remove the MSDOS c**p .
When you are happy with "newscriptname", you can of course issue:
Don't forget to check your solidii in the final script!
Just in case you don't get what is happening here. The carriage return character moves the cursor on your screen to the far left. Thus your field you expected to be on the right hand side was jumped to the left hand side and overwrote part of what had been already displayed. It's an effect on the screen. The "sed -l" version of the output from your script showed that the script itself is basically sound but that you need to pay some attention to solidii and the extra space character. The carriage-return characters just messed-up the output.
Important: You are destined to become a great Systems Administrator. You can present a problem clearly and follow instructions. Good luck in your future career.
Btw: Post #3 mentions csh. This Shell has no place in unix Systems Administration. My advice, don't use it.
Last edited by methyl; 12-13-2011 at 06:22 PM..
Reason: schoolboy error in mv ! assorted other typos
You are right, I initially created the script in my windows machine using notepad.
Could you please suggest any unix style editor that I can use in windows machine to create shell script?
Thanks Again.
KT.
PS:
Quote:
Important: You are destined to become a great Systems Administrator. You can present a problem clearly and follow instructions. Good luck in your future career.
Thanks, no disrespect to Sys Admins but I'm a J2EE developer
Btw. "Linux" is vague. The exact Operating System and version is more useful.
(blotting anything confidential like machine names with X's).
If you do edit on a Microsoft platform be careful how you transfer the file to the Linux/unix server. If you use ftp make sure that you use "text" mode because this will fix most of the usual issues. Temporarily renaming your file with a ".TXT" extension often helps with ftp.
Why not learn "vim" or one of the umpteen popular editors for Linux?
Btw. Whenever you mention an Operating System (e.g. "Windows") always state the manufacturer and version. e.g. Microsoft Windows 7 service pack 4,300. There are other more important uses of the word "Windows" in the unix world which precede Microsoft and are still in use today.
Hello All Unix Users,
I am still new to Unix, however I am eager to learn it..
I have 2 files, some lines have some matching substrings, I would like to concatenate these lines into one lines, leaving other untouched. Here below is an example for that..
File 1 (fasta file):
>292183... (6 Replies)
Alright, so I'm writing a file for the lexical analyzer (lex). It will be used to check C code (collecting the identifiers and storing those names along with the line numbers the identifier was found on). I'm not used to 'C' so I'm having some difficulty.
I am using a function (insertId()) to... (4 Replies)
Hi, all,
I tried to write a simple shell script as follow:
#!/bin/bash
# What want to do in bash is following
# : pcd_viewer cloud_cluster_0.pcd cloud_cluster_1.pcd cloud_cluster_2.pcd cloud_cluster_3.pcd cloud_cluster_4.pcd
STR = "pcd_viewer"
for i in `seq 0 4`
do
STR... (1 Reply)
I have these
str1=$(echo "This is string one with spaces \n This is also my sentence 1")
When I echo $str1, it displays the new line character properly.
Now I have another new variable say str2.
I want to concatenate in this way.. str1 + newline character + and then str2.
That's I... (3 Replies)
Hello,
I'm trying to run a program on a directory (traverse sub dirs too) through my csh script. Arrays support in CSH is appalling, something like associative arrays would have helped me do this so much easier.
Anyway, I want to hold some details extracted from the program and then at the... (0 Replies)
I m new to shell scripting and what i want is take as an i/p from command line the name of the file and inside my script i should redirect the o/p of my few commands to this file concatenated with .txt
for example if i give
./linux filename
i should get the o/p in filename.txt
i need to... (2 Replies)
Hi,
Well as the title says, I have an array of strings (delimited by null). The length of the array is variable and length of each string is variable as well. What I need is one huge string with the original strings in the array separated by spaces.
For example is an array is such that array... (12 Replies)
Hi all,
Think this is a pretty simple problem, but I've been thinking about it for a few days. Let's say that I'm going to have to output the contents of a file as the body of a mailx message.
I'll probably do this: cat <filename> | mailx <extra commands>
However, how do I go about doing... (1 Reply)
hey guys..
probably a simple question but i cant seem to find any info on it.
i have a small array of strings, and i want to concatenate the contents of the array into one big string.
any ideas on how i can do this?
cheers. (2 Replies)