I've no idea how this command works and I've no test environment to see it's output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers I've no idea how this command works and I've no test environment to see it's output
# 1  
Old 01-04-2012
I've no idea how this command works and I've no test environment to see it's output

Code:
`echo $variable | cut -c$((${#variable}))-`

I know the working of echo,pipe and cut to some extent.

Thanks in advance .

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by radoulov; 01-04-2012 at 07:48 AM.. Reason: Code tags!
# 2  
Old 01-04-2012
It attempts to eval the final character of the contents of $variable... probably not what you intended
cut -c <int> - returns the characters from the position int to the end of the string

((${#variable})) the ${#variable} construct returns the index of the last character of $variable, wrapping it in the numeric eval brackets doubly ensures an integer is returned
This User Gave Thanks to Skrynesaver For This Post:
# 3  
Old 01-04-2012
Thank you ,
I can understand your explanation but one more query , what does '#' do ?
Does it return the index of the variable ?

---------- Post updated at 05:08 PM ---------- Previous update was at 04:57 PM ----------

Got it sorry .
Reason : Brain Dead .

Last edited by Ion_Shell; 01-04-2012 at 07:34 AM.. Reason: I need to know the usage of # before the variable .
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script not working but command works in command prompt

Hi everyone I have a problem with my script If I try directly this command /usr/bin/nice -n 19 mysqldump -u root --password="******" wiki_schneider -c | nice -n 19 gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz It works But if I simply add this command in a script and... (8 Replies)
Discussion started by: picemma
8 Replies

2. Shell Programming and Scripting

Why my git command has no output in crontab but works well run this script manually?

cat /home/lyang001/update.sh #!/bin/sh #shopt -s expand_aliases HOME_DIR=/home/lyang001/updates UPDATE_MAIL=${HOME_DIR}/updates.mail rm $UPDATE_MAIL -rf cd $HOME_DIR/wr-kernel git log --no-merges --since="20 day ago" --name-status --pretty=format:"%an %h %s %cd" origin/WRLINUX_5_0_1_HEAD >>... (2 Replies)
Discussion started by: yanglei_fage
2 Replies

3. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

4. Shell Programming and Scripting

sed command works from cmd line to standard output but will not write to file

Hi all .... vexing problem here ... I am using sed to replace some special characters in a .txt file: sed -e 's/_<ED>_/_355_/g;s/_<F3>_/_363_/g;s/_<E1>_/_341_/g' filename.txt This command replaces <ED> with í , <F3> with ó and <E1> with á. When I run the command to standard output, it works... (1 Reply)
Discussion started by: crumplecrap
1 Replies

5. UNIX for Dummies Questions & Answers

How do i tell my bash shell script to test the output of a command against something

How do i tell my bash shell script to test the output of the command i'm using?? I want this script to look for lines not equal to 1 then let me know.. $ cat blah ; echo ---- ; cat blah.sh 1 fe 1 fi 1 fo 0 fum 1 blahda 1 blah 0 blahh 1 bla 1 bl 1 blahhh ---- #!/bin/bash while... (1 Reply)
Discussion started by: phpfreak
1 Replies

6. UNIX for Advanced & Expert Users

AIX, Solaris, Linux Test Environment Design Question

AIX, Solaris, Linux Test Environment Design Question We want to set an AIX, Solaris & Linux test environment. Here are the hardware equipments: (1) A Sunfire v100 (or v120), 1GB memory, two 36GB HDD. (2) An IBM pSeries 7026, 1 GB memory, 4 9GB HDD. (3) Five external HDD with SCSI... (1 Reply)
Discussion started by: aixlover
1 Replies

7. Solaris

AIX, Solaris, Linux Test Environment Design Question

AIX, Solaris, Linux Test Environment Design Question We want to set an AIX, Solaris & Linux test environment. Here are the hardware equipments: (1) A Sunfire v100 (or v120), 1GB memory, two 36GB HDD. (2) An IBM pSeries 7026, 1 GB memory, 4 9GB HDD. (3) Five external HDD with SCSI... (4 Replies)
Discussion started by: aixlover
4 Replies

8. Shell Programming and Scripting

Execution issue with shell script - works in a different environment

Hi I get the following error while executing the shell script. I did not get an error when I ran the script in a different environment (unix server). str-token.ksh: 0403-057 Syntax error at line 20 : `(' is not expected. This is the line which gives error string=(${pos_array}) Please find... (3 Replies)
Discussion started by: hidnana
3 Replies

9. Shell Programming and Scripting

Limitations of awk? Good idea? Bad idea?

Keeping in mind that I'm relatively comfortable with programming in general but very new to unix and korn/bourne shell scripts.. I'm using awk on a CSV file, and then performing calculations and operations on specific fields within specific records. The CSV file I'm working with has about 600... (2 Replies)
Discussion started by: yongho
2 Replies
Login or Register to Ask a Question