Inspecting leading char in string for slash


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Inspecting leading char in string for slash
# 1  
Old 07-16-2015
Inspecting leading char in string for slash

In a SCO Unix shop, I am working on the following script to move any file to its same location on the target machine (called 'othersy' here):
Code:

 pwd=`pwd`
 for i in "$@"
 do
 echo " $i "
 if [ $i -eq "^/.*" ] ; then echo 1; else echo 0; fi
 rcp -p $i othersy:$pwd/$i
 echo "Finished with ^[[7m$i^[[0m"
 done
 

If I find a file with a complete path name (leading slash, of course), I would not need to insert the "$pwd/" on the 'rcp' command. The echo 1 and echo 0 would be replaced with the appropriate 'rcp' command.

I had been experimenting with an if statement I found in a web search but what I found doesn't work on SCO.

TIA
# 2  
Old 07-16-2015
SCO should have ksh available? You didn't say which shell you're using.

You cannot use a regex but a shell pattern such as [[ "$i" = /* ]]
# 3  
Old 07-16-2015
Quote:
Originally Posted by neutronscott
SCO should have ksh available? You didn't say which shell you're using.

You cannot use a regex but a shell pattern such as [[ "$i" = /* ]]
I just tried if [[ "$i" = /* ]] ; then echo 1; else echo 0; fi
and got a message [[: not found and I got an echo of 0.

Thanks for looking at it.
# 4  
Old 07-16-2015
I implied you needed to use ksh for that. It should be your default shell, IMO, giving what SCO's documentation lists as available (ksh, csh, sh).

I don't have access to SCO but no sh should have a problem with:

Code:
case "$file" in
 /*) ;; # file already is absolute path
 *) file=$PWD/$file;; # prepend current path
esac

This User Gave Thanks to neutronscott For This Post:
# 5  
Old 07-17-2015
Many thanks, that did the trick!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace string until 3Rd occurance of forward slash(/)

I have a file abc.txt which has records like 456 /home/fgg/abdc.txt 3567 /home/fdss/vfgb.txt 23 /home/asd/dfght.txt I WANT TO REMOVE STRING UNTIL 3RD OCCURANCE OF FORWARD SLASH Output should be like abdc.txt vfgb.txt dfght.txt (5 Replies)
Discussion started by: himanshupant
5 Replies

2. Shell Programming and Scripting

awk pad 1 column with leading zero if char > 12

Hello, I got a question. I have several csv files with lots of data in it and for the first column i have EAN codes. The problem that i am facing is that some of these codes have the leading 0 removed so they are 12 or less chars while a EAN code is (always?) 13 chars. For this i used a... (9 Replies)
Discussion started by: SDohmen
9 Replies

3. Shell Programming and Scripting

Remove leading dot and slash on relative paths with find

When I specify a directory by name the leading ./ is not shown: $ find somedir/ somedir/a.bin somedir/target/out.binBut when I specify current dir it adds the ./ to the beginning of each result: $ find . | grep somedir ./somedir/a.bin ./somedir/target/out.binIs there any particular reason why... (2 Replies)
Discussion started by: Tribe
2 Replies

4. Shell Programming and Scripting

Strip leading and numbers from a string.

Hello I have two vars loaded with $VAR1="ISOMETHING103" $VAR2="COTHERTHING04" I need to: 1) Strip the first char. Could be sed 's/^.//' 2) The number has it's rules. If it has "hundreds", it needs to be striped. If it is just two digits it shouldn't. So, for VAR1 output should be... (7 Replies)
Discussion started by: tristezo2k
7 Replies

5. Shell Programming and Scripting

How to concatenate string containing a leading dash?

Is there a way to concatenate two strings, where the first string is "-n" and there is a space between the "-n" and the second string? Below are some examples of what I tried. #!/bin/sh var1=test #working without dashes: var2="n $var1" echo $var2 var2=n" "$var1 echo $var2 var2="n... (5 Replies)
Discussion started by: wolfv
5 Replies

6. Shell Programming and Scripting

Using sed to append backward slash before forward slash

Hi all, I need to know way of inserting backward slash before forward slash. My problem is that i need to supply directory path as an argument while invoking cshell script. This argument is further used in script (i.e. sed is used to insert this path in some file). So i need to place \ in front... (2 Replies)
Discussion started by: sarbjit
2 Replies

7. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

8. UNIX for Dummies Questions & Answers

trim leading zero in certain column in a string

I would like to know how to trim leading zero only in certain column of of a string, example: hdhshdhdhd000012mmmm0002abc <===== before hdhshdhdhd 12mmmm 2abc <===== after Thanks for your help. (2 Replies)
Discussion started by: dngo
2 Replies

9. Programming

touching a file which contains slash char

i need to create a file which contains (/) character. Any help to do this (1 Reply)
Discussion started by: axes
1 Replies

10. UNIX for Dummies Questions & Answers

Shell script: Cut / (slash) character in string

I have a string "\/scratch\/databases\". I want to have a new string "\/scratch\/databases" by cutting last '\' character using shell script. I can't do this Please help me. Thanks in advance ThuongTranVN (4 Replies)
Discussion started by: ThuongTranVN
4 Replies
Login or Register to Ask a Question