LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2013, 03:21 PM   #1
disciple218
LQ Newbie
 
Registered: Jan 2011
Posts: 5

Rep: Reputation: 0
Writing aliases with strings and variables


I'm working with a couple different screen sessions, and I want a way to detach and reattach without typing out the whole command with screen ID. I'm working with screen names that start with <PID>.mc255xx, where "xx" is a 2-digit number. I can reattach with "screen -r mc255xx" but I'd like an alias command "sr xx" for reattaching. Here's what I'm trying, to no avail:

alias sr='screen -r $(echo "mc255" + %1)'

Thanks in advance for helping a linux noob.
 
Old 11-18-2013, 03:29 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Some things you cannot do with an alias. You could create a function to do it:
Code:
function sr () {
  screen -r "mc255$1"
}
Put that in your ~/.bashrc file, (re-)open a terminal and if all went well you can now do sr xx

I am assuming you use bash.
 
Old 11-19-2013, 02:01 AM   #3
disciple218
LQ Newbie
 
Registered: Jan 2011
Posts: 5

Original Poster
Rep: Reputation: 0
This works perfectly! Thank you!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
using variables as strings in perl Elukyz Programming 9 06-17-2007 01:22 AM
argument variables in .bashrc's aliases? stabu Slackware 3 12-15-2006 12:30 PM
Get strings from list using variables mwade Programming 5 10-28-2006 09:01 PM
Newbie: Ruby and Writing Variables In Strings lmcilwain Programming 4 10-18-2006 02:19 PM
C++ converting strings to variables dhbiker Programming 9 05-31-2004 05:06 AM


All times are GMT -5. The time now is 10:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration