Thursday, September 6, 2012

Line Returns

The Setup
If you are running Linux as a guest OS within Windows using VirtualBox or VMware.
And if you have a Windows folder shared with Linux.
And if those folders have some shell scripts which you edit in Windows but execute in Linux.

Then there is a very high probability that you might get this error while running those script files on linux that were created in Windows:
$'clear\r': command not found 

I got this error for a simple hello world script:
# My first script
echo "Hello World!"

Windows represents End of Line (EOL) with two characters: CR + LF but Linux represents  End of Line (EOL)  with only LF (details)

So if you want to continue editing the source of these script file on Windows but run them on Linux, you will need to convert the EOL representations from Windows format to Linux format before you run the scripts on Linux.
If you are using Notepad++ as your source editor, you can achieve this by selecting the following option: Edit > EOL Conversion > UNIX Format

PS. This is important, otherwise your script files will be impotent! hah!

Carriage Return = CR = ASCII code 13 (in decimal) - '\r'
Line Feed = LF = ASCII code 10 (in decimal) - '\n'
These are vestiges of the typewriter era. There were two separate mechanical actions involved in beginning typing on a new line:

History: CR/LF goes back to the days of early printers where the codes
replicated the actions of a typewriter. CR (carriage return) returned
the carriage to the start of a new line. LF (line feed) advanced to the
next line. The lever at the left end of a typewriter combined moving
the carriage and advancing the line. Typists used to apply a CR/LF at
the end of every line and an extra CR/LF between paragraphs. As electric
typewriters came into use they would automatically apply the CR/LF when
the end of the line was reached. (link)

If you are editing Linux script files (bash) on Windows and are using GitHub for Windows to commit those files in one of your repositories, make sure to change the default line ending handling setting in your .gitattributes from:

# Auto detect text files and perform LF normalization
* text=auto


# Auto detect text files and perform LF normalization
* text eol=lf

You can then use Notepad++ to edit these script files on Windows and still use them properly on your Linux virtual machines (via shared folders on VirtualBox or VMware) without GitHub messing up the line conversion during commit and clone operations. Please note Windows' built-in notepad will not display these script files properly because it expects CR + LF as line endings and not just LF.

If in case you edited a script file on Windows using notepad and want to now execute on Linux, you can use the dos2unix utility to replace the CR-LF in a file with just LFs. After copying the script file to linux, execute the command:


and all line endings in your script file will be converted to linux format. Remember to "chmod +x" before you try to execute it.
You can get the dos2unix utility on Ubuntu (sudo apt-get install dos2unix) as well as on Arch Linux (pacman -S dos2unix).

Sunday, September 2, 2012

Mumbai Customs

The other day (11 June 2012) I ordered 2 units of APC. The VIA APC is a low-cost ($49) single-board computer designed to run the Android operating system. (wikipedia article).

The total cost was 49+49+35 = 133 USD.
The 35 USD was for shipping to Mumbai, India via Express Mail Service (EMS) (Official | wiki)

The transaction was carried out by Paypal on my credit card. (Exchange rate: 1 Indian Rupee = 0.0175420US Dollars)

The charge on my credit card appeared as 7581.80 INR (Indian Rupees) :

The original invoice was in USD (PDF sent to me via email):

The units were shipped on 27 July 2012 and the tracking was made available online the next day. Within 2 days the package had arrived in India, but it was withheld at the customs office for many days without any additional communications:

A week ago (27 August 2012 - a whole month after the device was shipped), I received a letter from the "Office of the commissioner of Customs (Import)":

The first crazy thing is this "request for documents" letter itself was dated 4 August 2012 and it reached me 3-4 weeks later even though both the source and the destination of the letter lie within the same city less than 10 kilometers apart. This is fucking pathetic - don't know why it's called snail mail, when its speed is worse than a snail's speed:

Average speed for the letter to reach me:
10 kilometers / 3 weeks =  10000/(21*24*60*60) meters/second= 0.0055 meters/seconds
A snail moves at 0.013 m/s (reference)

Anyway, so I read the letter and this is what I understood:

  1. Its illegal to import stuff having value of more than 2000 INR.
  2. But a friend can send you an article as "gift" worth upto 10,000 INR via EMS.
  3. If you violate the above rules, the article will be confiscated and you will be fined.
  4. In all cases, the value of the article must be established via proper documentation attached to the parcel or submitted in person (invoice, letter stating its a gift etc..)
And so, I called the phone number specified on the letter on Saturday,1st September 2012. The lady on the other end of the line (I had to call a couple of times before my call was answered) informed me of the following:
  1. The office is open in Saturdays (Oh joy!) but try to make it before 4pm
  2. The usual weekday timings are from 10 am to 5 pm. (This is in spite of what it says on the letter - that we can visit the office only between 3pm and 4 pm) (so oh joy! again!)
  3. I could mail them the documents via speed post.
  4. The package would be released on receiving valid documents and forwarded to my local post office for delivery and collecting any associated duty if any.
I decided to visit the office in person for two reasons: I wanted to know where this office was and how it worked and also I did not have any more patience to wait for the documents to reach them via super-snail mail. And so I visited the office the same day (1 September 2012). It was bang outside the domestic airport, here's a photo and a google map link:

Office of the commissioner of Customs (Import)
Airport Parcel Sorting office, Speed Post Centre, Opposite Hotel Sahara, Vile Parle (East), Mumbai 400099
Phone: +91 22  26156063

The security guard at the gate made an entry in visitors register which I signed and informed me that the offices I wanted to visit was on the first floor.

The first floor was sort of like a terrace/quadrangle with a passage running along its perimeter leading into various offices. I found the office that I wanted and saw a few people waiting outside it, the security guard stationed outside this office asked me to wait till the attended arrived. I was made to make an entry in a register specifying a BY number (specified on the letter which I had received) and asked to wait outside again till my package was located. About 45-60 mins later, I was called in again, and asked to produce documents affirming the value of the goods. I showed them printed copies of the invoice and the credit card accounts statement. They told me that a fine would be levied along with the duty: i.e. 5000 INR (fine) + 3110 INR (duty at 41% on 7581.80) = 8110 INR which is even more than the amount I paid for the goods. I told them that I had received goods of similar amount earlier and the was never fined, only a duty was levied. (I had collected my CuBox from my local post office by paying a duty of 3600 INR on the value of 8800 INR). The officers there opened the package in front of me and inspected the items within. They asked me if I was a student or a working professional and a few other personal question which I answered promptly. They agreed to impose only the custom duty on the device. They returned the invoice and other documents back to me and told me that the package would be forwarded to my local post office. From the there the postman will deliver the package to my home and collect the duty from me.

While exiting the office I met an agent/consultant of sorts which do the running around such government offices for you in case you want to import/export something. He told me that if I apply for an import/export code (IEC) from the Directorate General of Foreign Trade's website (, I would be able to cut down the hassles involved in clearing customs and also cut down the customs duty levied on the article. IEC can be applied for by individuals as well as registered companies and "seems" to be the "legally correct" way of getting stuff from abroad. He told me that if I had an IEC, the duty on the imported goods would be applied depending on the category of the goods instead of the flat 41% on the total value of the package. So in my case (electronic items) the duty would have been 16% instead of 41%. 

Also, I believe the duty would exclude the shipping costs of the article. Right now a flat 41% on the invoice amount means that I would be paying duty on the shipping charges which was a part of the invoice amount. This means that of 3110 INR that I have been asked to pay for the 2 units of APC, 800 INR is due to the 35 USD shipping charges.

I haven't yet gone through the foreign trade policies and procedures available on DGFT's website yet, but I guess if you regularly buy stuff over the internet from foreign firms, it would be in your interest to familiarize yourself with these rules and apply for an IEC code.

Wouldn't it be nice if we were given an overview of various departments of our government and their policies and procedures in school/college? It's such a pain to remain clueless for days all because you don't know which department to contact and you end up waiting for them to contact you.

So here's a short summary of my experiences of acquiring stuff from abroad:

Why would I want to buy stuff from abroad:

  1. It is not manufactured/sold locally in India.
  2. It is sold cheaper abroad and it will still be cheaper when you account for custom duty/shipping charges.
Ways of getting stuff into India:
  1. Hand carry: Buy stuff on your trip abroad and hand carry it in your luggage. There is a higher limit on the value of items you can carry without paying duty, but of course you have to wait for your (or your friend/family member's) next trip abroad (which is in itself expensive)
  2. Order stuff online using your credit card and get it sent to your friends place abroad and ask him/her to carry it back for you on his/her next visit home. The only shipping charges are that of the domestic type where the seller ships the item to your friends place abroad. Only thing is that you have to wait for your friends visit or keep a perpetual look out for home visit schedules of people staying abroad.
  3. Order stuff online and get it shipped via FedEx/UPS/DHL or some other professional shipping company: You get your goods really quick and the shipping company expedites and takes care of the customs assessment procedures and collecting duty from you. Downside is that shipping via these companies is expensive.
  4. Order stuff online and get it shipped via EMS/SpeedPost: Very cheap but very time consuming as the experience above shows.
There is another option of getting stuff India which I am going to try the next time: Order stuff online using your credit card and get it sent to your friends place abroad. Try to convince the seller to not include the shipping charges (even though it is domestic shipping between the warehouse and your friend's house) in the invoice - if possible as your friend to bear the shipping charges separately like for example using a FedEx account number etc. You can order stuff having value equivalent of upto 10,000 INR (i.e. 180 USD). Ask your friend to forward the package via EMS/SpeedPost with the invoice attached to the outside of the package clearly visible. Also ask him/her to include a letter (again attached to the outside of the package) saying that the items within the package are meant as a gift for you.

So, S and R, I am going to trouble you for this soon.

Update: 5 September 2012:

Update: Friday, 7 September 2012:
The package finally arrived, on the 6th day after visiting the customs office.
Had to pay the postman a duty of ~ INR 3100.
All in all, a very frustrating experience!

Lastly, a combined (source country and destination country information systems) tracking record of the parcel retrieved via International Postal System Web Tracking :