1828658 Members
1303 Online
109983 Solutions
New Discussion

Re: String & shell

 
cedber
Occasional Advisor

String & shell

Hello,

I try to play whith string in shell.
Exemple :
I want to convert the string "toto" in "tot[o]".
I don't want to use awk, sed, expr.... and i want it works with sh, bash and ksh.
So I have echo "v=echo ${var%?}" and "echo ${var##$v}" to split it. Then i just concat it...

But this works with bash and ksh but not with sh !

Is there someone who have an idea to make it ?!?

Thank's
3 REPLIES 3
Stuart Browne
Honored Contributor

Re: String & shell

When you say 'sh', which shell do you actually mean?

On most Linux systems, 'sh' will be a symbolic link to 'bash'.

If you're talking HP-UX's 'bourne' shell, then no, these won't work at all.

As far as I'm aware, there isn't that level of string manipulation with the bourne shell. You have to use either awk/sed/expr to get that sort of result.
One long-haired git at your service...
cedber
Occasional Advisor

Re: String & shell

In fact, i want to test a file existence. But it could be a symbolic link, a directory or other ... and it could be automounted !
with "echo /ect/passw[d]", for exemple, i can test it without be mounted. And "test -f" or other mount it...

If you have any idea.

Thank's
cedber
Occasional Advisor

Re: String & shell

I find a solution.

tmp=`echo $toto*`
set $tmp
res=`echo $1`

and i just compare $res and $toto to know if it's good...

CedBer