I have a Bash script that needs to know its full path. I'm trying to find a broadly-compatible way of doing that without ending up with relative or funky-looking paths. I only need to support Bash, not sh, csh, etc.  What I've found so far:   The accepted answer to  addresses getting the path of the script via dirname $0, which is fine, but that may return a relative path (like .), which is a problem if you want to change directories in the script and have the path still point to the script's directory. Still, dirname will be part of the puzzle. The accepted answer to  (OS X specific, but the answer works regardless) gives a function that will test to see if $0 looks relative and if so will pre-pend $PWD to it. But the result can still have relative bits in it (although overall it's absolute)&nbsp;&mdash; for instance, if the script is t in the directory /usr/bin and you're in /usr and you type bin/../bin/t to run it (yes, that's convoluted), you end up with /usr/bin/../bin as the script's directory path. Which works, but... The readlink solution , which looks like this:  # Absolute path to this script. /home/user/bin/foo.sh SCRIPT=$(readlink -f $0) # Absolute path this script is in. /home/user/bin SCRIPTPATH=`dirname $SCRIPT`   But readlink isn't POSIX and apparently the solution relies on GNU's readlink where BSD's won't work for some reason (I don't have access to a BSD-like system to check).   So, various ways of doing it, but they all have their caveats.  What would be a better way? Where "better" means:   Gives me the absolute path. Takes out funky bits even when invoked in a convoluted way (see comment on #2 above). (E.g., at least moderately canonicalizes the path.) Relies only on Bash-isms or things that are almost certain to be on most popular flavors of *nix systems (GNU/Linux, BSD and BSD-like systems like OS&nbsp;X, etc.). Avoids calling external programs if possible (e.g., prefers Bash built-ins). (Updated, thanks for the heads up, ) It doesn't have to resolve symlinks (in fact, I'd kind of prefer it left them alone, but that's not a requirement).
How do I get the path of the directory in which a  script is located, inside that script? I want to use a Bash script as a launcher for another application. I want to change the working directory to the one where the Bash script is located, so I can operate on the files in that directory, like so: $ ./application
Using a question mark mid-sentence 554 5.7.1 : Relay access denied centos postfix I have problem in send mail from postfix in centos  I have following  for sending mail but I am getting error.  As in the link I tried following commands  telnet localhost smtp  Trying ::1... Connected to localhost. Escape character is '^]'. 220 mydomain.com ESMTP Postfix ehlo localhost 250-mydomain.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN mail from:&lt;domain.com&gt; 250 2.1.0 Ok rcpt to:&lt;test@gmail.com&gt; 554 5.7.1 &lt;test@gmail.com&gt;: Relay access denied   Edit-1  In terminal this works  echo TEST | mail -v -s "Test mail" testing@gmail.com   my postconf -n shows belog information  alias_database = hash:/etc/aliases alias_maps = hash:/etc/aliases command_directory = /usr/sbin config_directory = /etc/postfix daemon_directory = /usr/libexec/postfix data_directory = /var/lib/postfix debug_peer_level = 2 home_mailbox = Maildir/ html_directory = no inet_interfaces = localhost inet_protocols = all mail_owner = postfix mailq_path = /usr/bin/mailq.postfix manpage_directory = /usr/share/man mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain mydomain = dummy.com myhostname = dummy.com mynetworks = all mynetworks_style = host myorigin = $mydomain newaliases_path = /usr/bin/newaliases.postfix queue_directory = /var/spool/postfix readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES sample_directory = /usr/share/doc/postfix-2.6.6/samples sendmail_path = /usr/sbin/sendmail.postfix setgid_group = postdrop unknown_local_recipient_reject_code = 550   What configuration I have to perform to send mails from my server. Change desktop background to a solid color (e.g. pitch black) in GNOME 3 How to merge partitions? I have two partitions, one of them has a file system and the other is unallocated.  How to merge two partitions? "The ticket is printing" vs "...is being printed" You're standing in front of a ticket vending machine and it says "The ticket is printing". Is that correct or should it be "The ticket is being printed"?  EDIT:  If both are correct, which one should be preferred or is more common? Standard example where Jacobson radical not equal nilradical Is Pauli-repulsion a "force" that is completely separate from the 4 fundamental forces? Can I re-enter the UK visa free shortly after Tier 2 visa expires? I get the following error when trying to ls *.txt | wc -l a directory that contains many files:  -bash: /bin/ls: Argument list too long   Does the threshold of this "Argument list" dependent on distro or computer's spec?  Usually, I'd pipe the result of such big result to some other commands (wc -l for example), so I'm not concerned with limits of the terminal. I'm trying to install texlive.  I proceeded in the recommended way, as per   After hours since initiating the download with install-tl as per instructions in . Hours after intiating the install-tl command, the installation aborted with the following error message:  Installing [2507/3271, time/total: 03:01:18/03:46:09]: rec-thy [221k] TLUtils::check_file: removing /tmp/bgLBEx3xxA/o1ankpQviV/rec-thy.tar.xz, sizes differ: TLUtils::check_file:   TL=0, arg=7428 TLPDB::_install_package: downloading did not succeed Installation failed. Rerunning the installer will try to restart the installation. Or you can restart by running the installer with:   install-tl --profile installation.profile [EXTRA-ARGS] install-tl: Writing log in current directory: /usr/local/src/install-tl-20160728/install-tl.log   I have no idea how to implement the crypic instruction  install-tl --profile installation.profile [EXTRA-ARGS]   because I can't find any information as what the EXTRA-ARGS should be, and google provided no help.    So I started again with   install-tl   hoping it would be smart enough not to start from scratch, but it wasn't, and did start from scratch, meaning another 3 hours.     This time it crashed after a few minutes, with   Installing [0051/3271, time/total: 04:08/04:30:47]: ae [84k] TLUtils::check_file: removing /tmp/ZLEUeUk8LV/ps7iOTjRWq/ae.tar.xz, sizes differ: TLUtils::check_file:   TL=43160, arg=57364 TLPDB::_install_package: downloading did not succeed Installation failed. Rerunning the installer will try to restart the installation. Or you can restart by running the installer with:   install-tl --profile installation.profile [EXTRA-ARGS] install-tl: Writing log in current directory: /usr/local/src/install-tl-20160728/install-tl.log   Why would the installation crash at different places?  Could somebody please interpret these crashes and how to prevent them?   If the installation crashes again, is there a way of picking up where I left off?   (presumably using the mysterious EXTRA-ARGS?).  If all else fails, is there another way of getting a less complete latex installation that will actually work?    Thanks very much for any advice? How to compare Unicode strings in Javascript? Here's an image from another question:    I get what the pull down resistor is there to do, but I don't really understand exactly how it works.  When there is no voltage applied through the base wire, why does any induced current then go through R2, but when a voltage is applied, it goes to the transistor? My understanding is that voltage always follows the path of least resistance, so if applying say, 5v turns the transistor on, that means that the transistor has a lower resistance than R2, so I would also assume any induced current would also flow through the resistor - so why does it then go through R2? I'm trying to make a page where a user provides an ID of a attachment and the site will set the headers and deliver that file instead of a 404 page. so /download/1754 would lookup the attachment with that Id and output it for viewing/download depending on the file type.  I just can't think of a wordpress friendly way to do this from inside a plugin. I considered using add_rewrite_rule but couldn't see a good way around it, also considered checking $_SERVER['REQUEST_URI'] to deliver the content before any HTML but then I'd have to stop the page from rendering a 404 and I was not sure of a Wordpress friendly way to do this.  My current idea was to have my plugin make a download page, assign a template and have that template run the logic instead of my plugin class. while I have used this before for another situation it was very messy as I had to write a lot of code to force users to be unable to update or edit the file and recreate/delete it on activation.deactivation. so ideally I'd like to avoid that. How do you make an image emission without washing out the image? Why does my iPhone power off when the battery is down to 30%? Today I was walking using my iPhone 6S running iOS 9.3 as a pedometer and it shutdown.   When I got home and plugged it in, it said 30% capacity.   That seems strange. I would expect it for 2% or 5% to preserve RAM, but 30%? Maybe there is a setting I don't know about.   My question is: Why does my iPhone power off when the battery is down to 30%?   Edit: this is not a duplicate of the low battery crash as I witnessed the low power shutdown and it was not a crash. How can I do a brute force (ciphertext only) attack on an CBC-encrypted message? Given a CBC ciphertext and IV, how can I find the encryption key?  We are limited with an 8 chars key, each char in the range of [a..h], so I can generate every possible key (these are only $8^8 = 2^{24}$ (about 4 million) different possible keys).  How would I go about finding the correct one though? How do I get an operating system onto a new hard drive? If $x$ and $y$ are not both $0$ then $ x^2 +xy +y^2> 0$ My phone was just stolen an hour or so ago. Are there any options for tracking? I realize this is a long shot, but my phone was lost or stolen a few hours ago.  At the time it was stolen, I didn't have any specific applications installed to track it or wipe the data. So... my bad. I'm hoping the fact that I have a pattern lock will at least prevent anyone from accessing my data.  My question is, do I have any options for tracking or data wipe after the fact? (I'm more interested in tracking.)  Note: I have read similar questions, but unless I'm mistaken, they all address the question in terms of preparation before losing the phone. I'm asking about fallback options after losing the phone. How to read and understand the java stack trace?